mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 18:02:05 +00:00
* 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
(cherry picked from commit eec1543baf)
This commit is contained in:
@@ -739,4 +739,4 @@ proc searchForBorrowProc(c: PContext, startScope: PScope, fn: PSym): PSym =
|
||||
result = nil
|
||||
elif result.magic in {mArrPut, mArrGet}:
|
||||
# cannot borrow these magics for now
|
||||
result = nil
|
||||
result = nil
|
||||
|
||||
@@ -70,6 +70,7 @@ type
|
||||
efNoUndeclared, efIsDotCall
|
||||
# Use this if undeclared identifiers should not raise an error during
|
||||
# overload resolution.
|
||||
efNoDiagnostics
|
||||
|
||||
TExprFlags* = set[TExprFlag]
|
||||
|
||||
|
||||
@@ -956,7 +956,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
|
||||
@@ -969,7 +969,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:
|
||||
@@ -1041,12 +1045,7 @@ 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]
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user