From afba2551dede5bebba707aed52ed82b655815447 Mon Sep 17 00:00:00 2001 From: Matthew Nibecker Date: Fri, 8 Dec 2023 11:16:24 -0700 Subject: [PATCH] semantic: return error on redefined constant (#4930) Closes #4684 --- compiler/semantic/scope.go | 3 +-- compiler/ztests/const-redefined-error.yaml | 6 ++++++ compiler/ztests/const-redefined-scope.yaml | 11 +++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 compiler/ztests/const-redefined-error.yaml create mode 100644 compiler/ztests/const-redefined-scope.yaml diff --git a/compiler/semantic/scope.go b/compiler/semantic/scope.go index 66122099fb..ba08f5986b 100644 --- a/compiler/semantic/scope.go +++ b/compiler/semantic/scope.go @@ -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) { diff --git a/compiler/ztests/const-redefined-error.yaml b/compiler/ztests/const-redefined-error.yaml new file mode 100644 index 0000000000..7bde18bf28 --- /dev/null +++ b/compiler/ztests/const-redefined-error.yaml @@ -0,0 +1,6 @@ +zed: | + type myport=int16 + type myport=int32 + put b:=type(myport) + +errorRE: 'symbol "myport" redefined' diff --git a/compiler/ztests/const-redefined-scope.yaml b/compiler/ztests/const-redefined-scope.yaml new file mode 100644 index 0000000000..ef1bf38f83 --- /dev/null +++ b/compiler/ztests/const-redefined-scope.yaml @@ -0,0 +1,11 @@ +zed: | + const a=1 + ( + const a=2 + yield a + ) + +input: 'null' + +output: | + 2