Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sem): crash with procedure with error used as argument #1443

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/sem/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3561,6 +3561,10 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
result = symChoice(c, n, s, scClosed)
if result.kind == nkSym:
markIndirect(c, result.sym)
# the symbol was alrady marked as used, don't mark it as such again
# (via ``semSym``)
if result.sym.ast.isError:
result = c.config.newError(result, PAstDiag(kind: adWrappedSymError))
of skEnumField:
if overloadableEnums in c.features:
result = enumFieldSymChoice(c, n, s)
Expand Down
4 changes: 2 additions & 2 deletions compiler/sem/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2602,9 +2602,9 @@ proc paramTypesMatch*(

else:
# only one valid interpretation found, executing argument match
markUsed(candidate.c, arg.info, arg[bestArg].sym)
let realArg = candidate.c.semExpr(c, arg[bestArg], {})
result = paramTypesMatchAux(
candidate, formal, arg[bestArg].typ, arg[bestArg])
candidate, formal, realArg.typ, realArg)

when false:
if candidate.calleeSym != nil and
Expand Down
15 changes: 15 additions & 0 deletions tests/error_propagation/tgeneric_proc_sym_as_argument.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
discard """
description: '''
Ensure that generic procedure symbols are wrapped in an error, when used
in an argument context
'''
action: reject
matrix: "--errorMax:100"
"""

proc call(p: proc(x: int)) = discard

proc withError[T](x: T) =
missing

call(withError) # <- this crashed the compiler
18 changes: 18 additions & 0 deletions tests/error_propagation/toverloaded_proc_sym_as_argument.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
discard """
description: '''
Ensure that overloaded procedure symbols are wrapped in an error, when
used in an argument context
'''
action: reject
matrix: "--errorMax:100"
"""

proc call(p: proc()) = discard

proc withError() =
missing

proc withError(a: int) = # <- this overload is not picked below
discard

call(withError) # <- this crashed the compiler
15 changes: 15 additions & 0 deletions tests/error_propagation/tproc_sym_as_argument.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
discard """
description: '''
Ensure that procedure symbols are wrapped in an error, when used in an
argument context
'''
action: reject
matrix: "--errorMax:100"
"""

proc call(p: proc()) = discard

proc withError() =
missing

call(withError) # <- this crashed the compiler
Loading