diff options
-rw-r--r-- | compiler/semexprs.nim | 3 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 5 | ||||
-rw-r--r-- | tests/misc/t20883.nim | 12 |
3 files changed, 20 insertions, 0 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 398424bbf..b7fc7a9bd 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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): diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index d1b3b5dfb..12cc1fcb1 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -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) diff --git a/tests/misc/t20883.nim b/tests/misc/t20883.nim new file mode 100644 index 000000000..d98feaa14 --- /dev/null +++ b/tests/misc/t20883.nim @@ -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() |