* 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
This commit is contained in:
parent
6166b796ba
commit
eec1543baf
4 changed files with 41 additions and 8 deletions
|
|
@ -402,6 +402,9 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
|
||||||
if overloadsState == csEmpty and result.state == csEmpty:
|
if overloadsState == csEmpty and result.state == csEmpty:
|
||||||
if efNoUndeclared notin flags: # for tests/pragmas/tcustom_pragma.nim
|
if efNoUndeclared notin flags: # for tests/pragmas/tcustom_pragma.nim
|
||||||
template impl() =
|
template impl() =
|
||||||
|
result.state = csNoMatch
|
||||||
|
if efNoDiagnostics in flags:
|
||||||
|
return
|
||||||
# xxx adapt/use errorUndeclaredIdentifierHint(c, n, f.ident)
|
# xxx adapt/use errorUndeclaredIdentifierHint(c, n, f.ident)
|
||||||
localError(c.config, n.info, getMsgDiagnostic(c, flags, n, f))
|
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:
|
if n[0].kind == nkIdent and n[0].ident.s == ".=" and n[2].kind == nkIdent:
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ type
|
||||||
efSkipFieldVisibilityCheck
|
efSkipFieldVisibilityCheck
|
||||||
# Use this if undeclared identifiers should not raise an error during
|
# Use this if undeclared identifiers should not raise an error during
|
||||||
# overload resolution.
|
# overload resolution.
|
||||||
|
efNoDiagnostics
|
||||||
|
|
||||||
TExprFlags* = set[TExprFlag]
|
TExprFlags* = set[TExprFlag]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1004,7 +1004,7 @@ proc handleCaseStmtMacro(c: PContext; n: PNode; flags: TExprFlags): PNode =
|
||||||
toResolve.add n[0]
|
toResolve.add n[0]
|
||||||
|
|
||||||
var errors: CandidateErrors
|
var errors: CandidateErrors
|
||||||
var r = resolveOverloads(c, toResolve, toResolve, {skTemplate, skMacro}, {},
|
var r = resolveOverloads(c, toResolve, toResolve, {skTemplate, skMacro}, {efNoDiagnostics},
|
||||||
errors, false)
|
errors, false)
|
||||||
if r.state == csMatch:
|
if r.state == csMatch:
|
||||||
var match = r.calleeSym
|
var match = r.calleeSym
|
||||||
|
|
@ -1017,7 +1017,11 @@ proc handleCaseStmtMacro(c: PContext; n: PNode; flags: TExprFlags): PNode =
|
||||||
case match.kind
|
case match.kind
|
||||||
of skMacro: result = semMacroExpr(c, toExpand, toExpand, match, flags)
|
of skMacro: result = semMacroExpr(c, toExpand, toExpand, match, flags)
|
||||||
of skTemplate: result = semTemplateExpr(c, 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',
|
# 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
|
# but it kinda sucks for pattern matching as the matcher is not attached to
|
||||||
# a type then:
|
# a type then:
|
||||||
|
|
@ -1088,12 +1092,8 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil
|
||||||
else:
|
else:
|
||||||
popCaseContext(c)
|
popCaseContext(c)
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
#if caseStmtMacros in c.features:
|
return handleCaseStmtMacro(c, n, flags)
|
||||||
result = handleCaseStmtMacro(c, n, flags)
|
|
||||||
if result != nil:
|
|
||||||
return result
|
|
||||||
localError(c.config, n[0].info, errSelectorMustBeOfCertainTypes)
|
|
||||||
return
|
|
||||||
for i in 1..<n.len:
|
for i in 1..<n.len:
|
||||||
setCaseContextIdx(c, i)
|
setCaseContextIdx(c, i)
|
||||||
var x = n[i]
|
var x = n[i]
|
||||||
|
|
|
||||||
29
tests/errmsgs/tcase_stmt.nim
Normal file
29
tests/errmsgs/tcase_stmt.nim
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
discard """
|
||||||
|
cmd: "nim check --hints:off $file"
|
||||||
|
errormsg: ""
|
||||||
|
nimout: '''
|
||||||
|
tcase_stmt.nim(22, 7) Error: selector must be of an ordinal type, float or string
|
||||||
|
tcase_stmt.nim(28, 6) Error: selector must be of an ordinal type, float or string
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# bug #19682
|
||||||
|
type A = object
|
||||||
|
|
||||||
|
case A()
|
||||||
|
else:
|
||||||
|
discard
|
||||||
|
|
||||||
|
# bug #20283
|
||||||
|
|
||||||
|
case @[]
|
||||||
|
else: discard
|
||||||
Loading…
Add table
Add a link
Reference in a new issue