fixes #15533 [backport:1.4]

This commit is contained in:
Araq
2020-10-23 10:33:41 +02:00
parent 64016ddedc
commit 039f57ec4b
2 changed files with 19 additions and 3 deletions

View File

@@ -92,6 +92,7 @@ type
isSubtype,
isSubrange, # subrange of the wanted type; no type conversion
# but apart from that counts as ``isSubtype``
isVarConvertible,
isBothMetaConvertible # generic proc parameter was matched against
# generic type, e.g., map(mySeq, x=>x+1),
# maybe recoverable by rerun if the parameter is
@@ -1191,7 +1192,10 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
of tyFloat128: result = handleFloatRange(f, a)
of tyVar, tyLent:
if aOrig.kind == f.kind: result = typeRel(c, f.base, aOrig.base, flags)
else: result = typeRel(c, f.base, aOrig, flags + {trNoCovariance})
else:
result = typeRel(c, f.base, aOrig, flags + {trNoCovariance})
if result > isVarConvertible:
result = isVarConvertible
subtypeCheck()
of tyArray:
case a.kind
@@ -1976,7 +1980,7 @@ proc incMatches(m: var TCandidate; r: TTypeRelation; convMatch = 1) =
of isFromIntLit: inc(m.intConvMatches, 256)
of isInferredConvertible:
inc(m.convMatches)
of isEqual: inc(m.exactMatches)
of isEqual, isVarConvertible: inc(m.exactMatches)
of isNone: discard
template matchesVoidProc(t: PType): bool =
@@ -2126,7 +2130,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
# ``isIntConv`` and ``isIntLit`` here:
inc(m.intConvMatches, 256)
result = implicitConv(nkHiddenStdConv, f, arg, m, c)
of isEqual:
of isEqual, isVarConvertible:
inc(m.exactMatches)
result = arg
if skipTypes(f, abstractVar-{tyTypeDesc}).kind == tyTuple or

View File

@@ -0,0 +1,12 @@
discard """
errormsg: "type mismatch: got <Option[system.int]> but expected 'Option[var int]'"
cmd: "nim check $file"
line: 12
"""
# bug #15533
{.experimental: "views".}
import options
var a = [1, 2, 3, 4]
let o: Option[var int] = some(a[0])