Skip to content

Commit

Permalink
semantic: return error on redefined constant (#4930)
Browse files Browse the repository at this point in the history
Closes #4684
  • Loading branch information
mattnibs authored Dec 8, 2023
1 parent cbd5bbd commit afba255
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/semantic/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func (s *Scope) DefineConst(zctx *zed.Context, name string, def dag.Expr) error
Kind: "Literal",
Value: zson.FormatValue(val),
}
s.DefineAs(name, literal)
return nil
return s.DefineAs(name, literal)
}

func (s *Scope) LookupExpr(name string) (dag.Expr, error) {
Expand Down
6 changes: 6 additions & 0 deletions compiler/ztests/const-redefined-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
zed: |
type myport=int16
type myport=int32
put b:=type(myport)
errorRE: 'symbol "myport" redefined'
11 changes: 11 additions & 0 deletions compiler/ztests/const-redefined-scope.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
zed: |
const a=1
(
const a=2
yield a
)
input: 'null'

output: |
2

0 comments on commit afba255

Please sign in to comment.