Skip to content

Commit

Permalink
disallow enum is .BoxedType(&val)
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Jan 2, 2024
1 parent 51c6e24 commit eff3174
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions rivetc/src/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ def check_expr(self, expr):
if lsym.kind == TypeKind.Enum and lsym.info.is_tagged:
v_t = expr.right.variant_info.typ
if expr.var.is_ref:
if v_t.value_is_boxed():
report.error("cannot take reference to a boxed value", expr.var.pos)
v_t = type.Ptr(v_t, expr.var.is_mut)
if expr.right.variant_info.has_typ:
expr.scope.update_type(expr.var.name, v_t)
Expand All @@ -804,12 +806,16 @@ def check_expr(self, expr):
else:
v_t = rtyp
if expr.var.is_ref:
if v_t.value_is_boxed():
report.error("cannot take reference to a boxed value", expr.var.pos)
v_t = type.Ptr(rtyp, expr.var.is_mut)
expr.scope.update_type(expr.var.name, v_t)
expr.var.typ = v_t
if expr.var.is_mut:
self.check_expr_is_mut(expr.left)
if not expr.var.is_ref:
report.error("invalid syntax for typematching", expr.var.pos)
report.help("use `&mut` instead")
expr.scope.update_is_hidden_ref(expr.var.name, True)
if lsym.kind == TypeKind.Enum:
if lsym.info.is_tagged and expr.op not in (
Expand Down Expand Up @@ -1474,26 +1480,34 @@ def check_expr(self, expr):
report.error(e.args[0], p.pos)
if b.has_var:
if b.var_is_mut:
self.check_expr_is_mut(expr.expr)
if b.var_is_ref:
self.check_expr_is_mut(expr.expr)
else:
report.error("invalid syntax for typematching", expr.var_pos)
report.help("use `&mut` instead")
if len(b.pats) == 1:
var_t = self.comp.void_t
if expr_sym.kind == TypeKind.Enum:
pat0 = b.pats[0].variant_info
if pat0.has_typ:
var_t = pat0.typ
if b.var_is_ref:
if var_t.value_is_boxed():
report.error("cannot take reference to a boxed value", b.var_pos)
var_t = type.Ptr(var_t, b.var_is_mut)
else:
report.error(
"cannot use void expression",
b.pats[0].pos
b.var_pos
)
if not b.var_is_ref:
b.scope.update_is_hidden_ref(
b.var_name, b.var_is_mut
)
else:
var_t = b.pats[0].typ
if b.var_is_ref and var_t.value_is_boxed():
report.error("cannot take reference to a boxed value", b.var_pos)
b.var_typ = var_t
b.scope.update_type(b.var_name, var_t)
else:
Expand Down

0 comments on commit eff3174

Please sign in to comment.