From 5541d25f123e17d51b798f39065c53b897d0f513 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 7 Nov 2022 00:24:41 +0800 Subject: [PATCH] fix #12559 Referring to a static nil param is impossible --- compiler/semexprs.nim | 2 ++ compiler/sigmatch.nim | 3 +++ tests/statictypes/t12559.nim | 13 +++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/statictypes/t12559.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 39649fa271222..c7997620335da 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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 diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 73d742f1a8ade..b12c212db9cda 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -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: diff --git a/tests/statictypes/t12559.nim b/tests/statictypes/t12559.nim new file mode 100644 index 0000000000000..6547e6b22586e --- /dev/null +++ b/tests/statictypes/t12559.nim @@ -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