mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-05 20:47:53 +00:00
* fix #20883 Unspecified generic on default value segfaults the compiler
* fallback to isGeneric
* change to closer error
* Update t20883.nim
(cherry picked from commit 26f183043f)
This commit is contained in:
@@ -238,6 +238,9 @@ proc checkConvertible(c: PContext, targetTyp: PType, src: PNode): TConvStatus =
|
||||
result = convNotInRange
|
||||
else:
|
||||
# we use d, s here to speed up that operation a bit:
|
||||
if d.kind == tyFromExpr:
|
||||
result = convNotLegal
|
||||
return
|
||||
case cmpTypes(c, d, s)
|
||||
of isNone, isGeneric:
|
||||
if not compareTypes(targetTyp.skipTypes(abstractVar), srcTyp.skipTypes({tyOwned}), dcEqIgnoreDistinct):
|
||||
|
||||
@@ -819,6 +819,8 @@ proc tryResolvingStaticExpr(c: var TCandidate, n: PNode,
|
||||
# This proc is used to evaluate such static expressions.
|
||||
let instantiated = replaceTypesInBody(c.c, c.bindings, n, nil,
|
||||
allowMetaTypes = allowUnresolved)
|
||||
if instantiated.kind in nkCallKinds:
|
||||
return nil
|
||||
result = c.c.semExpr(c.c, instantiated)
|
||||
|
||||
proc inferStaticParam*(c: var TCandidate, lhs: PNode, rhs: BiggestInt): bool =
|
||||
@@ -1887,6 +1889,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
|
||||
# fix the expression, so it contains the already instantiated types
|
||||
if f.n == nil or f.n.kind == nkEmpty: return isGeneric
|
||||
let reevaluated = tryResolvingStaticExpr(c, f.n)
|
||||
if reevaluated == nil:
|
||||
result = isNone
|
||||
return
|
||||
case reevaluated.typ.kind
|
||||
of tyTypeDesc:
|
||||
result = typeRel(c, a, reevaluated.typ.base, flags)
|
||||
|
||||
12
tests/misc/t20883.nim
Normal file
12
tests/misc/t20883.nim
Normal file
@@ -0,0 +1,12 @@
|
||||
discard """
|
||||
action: reject
|
||||
errormsg: "type mismatch: got <float64> but expected 'typeof(U(0.000001))'"
|
||||
line: 8
|
||||
column: 22
|
||||
"""
|
||||
|
||||
proc foo*[U](x: U = U(1e-6)) =
|
||||
echo x
|
||||
|
||||
foo[float]()
|
||||
foo()
|
||||
Reference in New Issue
Block a user