mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-26 01:04:00 +00:00
fix for bad error message with const in case statement (#21182)
* preliminary fix for bad error message with const * add test case * fix tmatrixconcept and tmatrixlib
This commit is contained in:
@@ -569,6 +569,8 @@ proc foldDefine(m, s: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode
|
||||
else: result = copyTree(s.astdef) # unreachable
|
||||
else:
|
||||
result = copyTree(s.astdef)
|
||||
if result != nil:
|
||||
result.info = n.info
|
||||
|
||||
proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode =
|
||||
result = nil
|
||||
@@ -593,6 +595,8 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode
|
||||
result = foldDefine(m, s, n, idgen, g)
|
||||
else:
|
||||
result = copyTree(s.astdef)
|
||||
if result != nil:
|
||||
result.info = n.info
|
||||
of skProc, skFunc, skMethod:
|
||||
result = n
|
||||
of skParam:
|
||||
|
||||
7
tests/errmsgs/tconstinfo.nim
Normal file
7
tests/errmsgs/tconstinfo.nim
Normal file
@@ -0,0 +1,7 @@
|
||||
# https://forum.nim-lang.org/t/9762
|
||||
|
||||
const foo = "abc"
|
||||
case 'a'
|
||||
of foo: echo "should error" #[tt.Error
|
||||
^ type mismatch: got <string> but expected 'char']#
|
||||
else: discard
|
||||
Reference in New Issue
Block a user