diff options
author | Bung <crc32@qq.com> | 2022-11-01 17:19:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-01 10:19:37 +0100 |
commit | eec1543baf10715c7107133aaf6aa1e4932f53fe (patch) | |
tree | edf5ff12af3cfbb81e4ec41c78866b9d703ea62b /compiler | |
parent | 6166b796ba159f8aaeb741cc2359ae32037262eb (diff) | |
download | Nim-eec1543baf10715c7107133aaf6aa1e4932f53fe.tar.gz |
fix semcase on tySequence and tyObject #20283 #19682 (#20339)
* fix semcase on tySequence and tyObject #20283 #19682 * use better arg name * avoiding returns nil use errorNode instead, clean code * use efNoDiagnostics flag * remove tests/errmsgs/t19682.nim * combine 2 test cases to one file
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semcall.nim | 3 | ||||
-rw-r--r-- | compiler/semdata.nim | 1 | ||||
-rw-r--r-- | compiler/semstmts.nim | 16 |
3 files changed, 12 insertions, 8 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim index ed8699a26..fa5cee69a 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -402,6 +402,9 @@ proc resolveOverloads(c: PContext, n, orig: PNode, if overloadsState == csEmpty and result.state == csEmpty: if efNoUndeclared notin flags: # for tests/pragmas/tcustom_pragma.nim template impl() = + result.state = csNoMatch + if efNoDiagnostics in flags: + return # xxx adapt/use errorUndeclaredIdentifierHint(c, n, f.ident) localError(c.config, n.info, getMsgDiagnostic(c, flags, n, f)) if n[0].kind == nkIdent and n[0].ident.s == ".=" and n[2].kind == nkIdent: diff --git a/compiler/semdata.nim b/compiler/semdata.nim index d1ffab5eb..2442030f5 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -73,6 +73,7 @@ type efSkipFieldVisibilityCheck # Use this if undeclared identifiers should not raise an error during # overload resolution. + efNoDiagnostics TExprFlags* = set[TExprFlag] diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 596995adb..bf1fe4050 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1004,7 +1004,7 @@ proc handleCaseStmtMacro(c: PContext; n: PNode; flags: TExprFlags): PNode = toResolve.add n[0] var errors: CandidateErrors - var r = resolveOverloads(c, toResolve, toResolve, {skTemplate, skMacro}, {}, + var r = resolveOverloads(c, toResolve, toResolve, {skTemplate, skMacro}, {efNoDiagnostics}, errors, false) if r.state == csMatch: var match = r.calleeSym @@ -1017,7 +1017,11 @@ proc handleCaseStmtMacro(c: PContext; n: PNode; flags: TExprFlags): PNode = case match.kind of skMacro: result = semMacroExpr(c, toExpand, toExpand, match, flags) of skTemplate: result = semTemplateExpr(c, toExpand, match, flags) - else: result = nil + else: result = errorNode(c, n[0]) + elif r.state == csNoMatch: + result = errorNode(c, n[0]) + if result.kind == nkEmpty: + localError(c.config, n[0].info, errSelectorMustBeOfCertainTypes) # this would be the perfectly consistent solution with 'for loop macros', # but it kinda sucks for pattern matching as the matcher is not attached to # a type then: @@ -1088,12 +1092,8 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil else: popCaseContext(c) closeScope(c) - #if caseStmtMacros in c.features: - result = handleCaseStmtMacro(c, n, flags) - if result != nil: - return result - localError(c.config, n[0].info, errSelectorMustBeOfCertainTypes) - return + return handleCaseStmtMacro(c, n, flags) + for i in 1..<n.len: setCaseContextIdx(c, i) var x = n[i] |