Skip to content

Commit aa1bca8

Browse files
committed
jule: make error variable isolated from mutation and sharing
1 parent 1423ff0 commit aa1bca8

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

std/jule/sema/eval.jule

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,6 +3920,15 @@ impl unaryEval {
39203920
|:
39213921
match {
39223922
| canGetPtr(self.v):
3923+
// If the value is error, complain.
3924+
var, _ := self.v.Model.(&Var)
3925+
if var != nil && var.Name == "error" {
3926+
self.e.pushErr(self.u.X.Token, "cannot take pointer of the error value")
3927+
self.e.pushSuggestion("use an intermediary variable: myerr := error; &myerr")
3928+
self.v.Decl = true
3929+
ret
3930+
}
3931+
39233932
self.v.Type = &Type{
39243933
Kind: &Ptr{Value: self.v.Type},
39253934
}

std/jule/sema/scope.jule

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,13 @@ fn checkAssign(mut s: &sema, mut left: &Value, mut right: &Value, op: &token::To
28342834
ret false
28352835
}
28362836

2837+
// If the value is error, complain.
2838+
var, _ := left.Model.(&Var)
2839+
if var != nil && var.Name == "error" {
2840+
s.pushErr(op, "cannot assign to the error value")
2841+
ret false
2842+
}
2843+
28372844
f := left.Type.Func()
28382845
if f != nil && f.Decl != nil && f.Decl.Global {
28392846
// Make sure function is indeed a global function.

0 commit comments

Comments
 (0)