fixes 9195 (#12055)
This commit is contained in:
parent
5a9edb222b
commit
b044523c5a
3 changed files with 35 additions and 3 deletions
|
|
@ -1040,6 +1040,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
|
|
||||||
of tyGenericInvocation:
|
of tyGenericInvocation:
|
||||||
for i in 1 ..< paramType.len:
|
for i in 1 ..< paramType.len:
|
||||||
|
#if paramType[i].kind != tyTypeDesc:
|
||||||
let lifted = recurse(paramType.sons[i])
|
let lifted = recurse(paramType.sons[i])
|
||||||
if lifted != nil: paramType.sons[i] = lifted
|
if lifted != nil: paramType.sons[i] = lifted
|
||||||
|
|
||||||
|
|
@ -1355,7 +1356,10 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
|
||||||
|
|
||||||
for i in 1 ..< m.call.len:
|
for i in 1 ..< m.call.len:
|
||||||
var typ = m.call[i].typ
|
var typ = m.call[i].typ
|
||||||
if typ.kind == tyTypeDesc and typ.sons[0].kind == tyNone:
|
# is this a 'typedesc' *parameter*? If so, use the typedesc type,
|
||||||
|
# unstripped.
|
||||||
|
if m.call[i].kind == nkSym and m.call[i].sym.kind == skParam and
|
||||||
|
typ.kind == tyTypeDesc and containsGenericType(typ):
|
||||||
isConcrete = false
|
isConcrete = false
|
||||||
addToResult(typ)
|
addToResult(typ)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1654,8 +1654,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
|
||||||
of tyGenericParam:
|
of tyGenericParam:
|
||||||
var x = PType(idTableGet(c.bindings, f))
|
var x = PType(idTableGet(c.bindings, f))
|
||||||
if x == nil:
|
if x == nil:
|
||||||
if c.callee.kind == tyGenericBody and
|
if c.callee.kind == tyGenericBody and not c.typedescMatched:
|
||||||
f.kind == tyGenericParam and not c.typedescMatched:
|
|
||||||
# XXX: The fact that generic types currently use tyGenericParam for
|
# XXX: The fact that generic types currently use tyGenericParam for
|
||||||
# their parameters is really a misnomer. tyGenericParam means "match
|
# their parameters is really a misnomer. tyGenericParam means "match
|
||||||
# any value" and what we need is "match any type", which can be encoded
|
# any value" and what we need is "match any type", which can be encoded
|
||||||
|
|
@ -1700,6 +1699,11 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
|
||||||
c.inheritancePenalty = oldInheritancePenalty - c.inheritancePenalty -
|
c.inheritancePenalty = oldInheritancePenalty - c.inheritancePenalty -
|
||||||
100 * ord(result == isEqual)
|
100 * ord(result == isEqual)
|
||||||
result = isGeneric
|
result = isGeneric
|
||||||
|
elif a.kind == tyTypeDesc:
|
||||||
|
# somewhat special typing rule, the following is illegal:
|
||||||
|
# proc p[T](x: T)
|
||||||
|
# p(int)
|
||||||
|
result = isNone
|
||||||
else:
|
else:
|
||||||
result = isGeneric
|
result = isGeneric
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,3 +48,27 @@ doAssert hasDefault2(int) == "int"
|
||||||
doAssert hasDefault2(string) == "string"
|
doAssert hasDefault2(string) == "string"
|
||||||
doAssert hasDefault2() == "string"
|
doAssert hasDefault2() == "string"
|
||||||
|
|
||||||
|
|
||||||
|
# bug #9195
|
||||||
|
type
|
||||||
|
Error = enum
|
||||||
|
erA, erB, erC
|
||||||
|
Result[T, U] = object
|
||||||
|
x: T
|
||||||
|
u: U
|
||||||
|
PB = object
|
||||||
|
|
||||||
|
proc decodeUVarint*(itzzz: typedesc[SomeUnsignedInt],
|
||||||
|
data: openArray[char]): Result[itzzz, Error] =
|
||||||
|
result = Result[itzzz, Error](x: 0, u: erC)
|
||||||
|
|
||||||
|
discard decodeUVarint(uint32, "abc")
|
||||||
|
|
||||||
|
type
|
||||||
|
X = object
|
||||||
|
Y[T] = object
|
||||||
|
|
||||||
|
proc testObj(typ: typedesc[object]): Y[typ] =
|
||||||
|
discard
|
||||||
|
|
||||||
|
discard testObj(X)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue