Skip to content

Commit

Permalink
fix nim-lang#12559 Referring to a static nil param is impossible
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Nov 6, 2022
1 parent fc8bfd7 commit 5541d25
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,8 @@ proc builtinFieldAccess(c: PContext; n: PNode; flags: var TExprFlags): PNode =
return

n[0] = semExprWithType(c, n[0], flags+{efDetermineType, efWantIterable})
if n[0].kind == nkNilLit:
localError(c.config, n.info, "nil literal access")
#restoreOldStyleType(n[0])
var i = considerQuotedIdent(c, n[1], n)
var ty = n[0].typ
Expand Down
3 changes: 3 additions & 0 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,9 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
inc(m.subtypeMatches)
if f.kind == tyTypeDesc:
result = arg
elif f.skipTypes({tyStatic}).kind in {tyRef,tyPtr} and
arg.typ.skipTypes({tyStatic}).kind == tyNil:
result = arg
else:
result = implicitConv(nkHiddenSubConv, f, arg, m, c)
of isSubrange:
Expand Down
13 changes: 13 additions & 0 deletions tests/statictypes/t12559.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
discard """
errormsg: '''nil literal access'''
line: 11
"""



type T = ref object
x: int

proc f(arg:static T) = discard arg.x

f nil

0 comments on commit 5541d25

Please sign in to comment.