mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-22 19:06:50 +00:00
fixes #11257
This commit is contained in:
@@ -329,7 +329,7 @@ proc describeArgs*(c: PContext, n: PNode, startIdx = 1;
|
||||
proc typeRel*(c: var TCandidate, f, aOrig: PType,
|
||||
flags: TTypeRelFlags = {}): TTypeRelation
|
||||
|
||||
proc concreteType(c: TCandidate, t: PType): PType =
|
||||
proc concreteType(c: TCandidate, t: PType; f: PType = nil): PType =
|
||||
case t.kind
|
||||
of tyNil:
|
||||
result = nil # what should it be?
|
||||
@@ -351,6 +351,13 @@ proc concreteType(c: TCandidate, t: PType): PType =
|
||||
of tyGenericInvocation:
|
||||
result = t
|
||||
doAssert(false, "cannot resolve type: " & typeToString(t))
|
||||
of tyOwned:
|
||||
# bug #11257: the comparison system.`==`[T: proc](x, y: T) works
|
||||
# better without the 'owned' type:
|
||||
if f != nil and f.len > 0 and f.sons[0].skipTypes({tyBuiltInTypeClass}).kind == tyProc:
|
||||
result = t.lastSon
|
||||
else:
|
||||
result = t
|
||||
else:
|
||||
result = t # Note: empty is valid here
|
||||
|
||||
@@ -1663,9 +1670,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
|
||||
# check if 'T' has a constraint as in 'proc p[T: Constraint](x: T)'
|
||||
if f.sonsLen > 0 and f.sons[0].kind != tyNone:
|
||||
let oldInheritancePenalty = c.inheritancePenalty
|
||||
result = typeRel(c, f.lastSon, a, flags + {trDontBind})
|
||||
result = typeRel(c, f.sons[0], a, flags + {trDontBind})
|
||||
if doBind and result notin {isNone, isGeneric}:
|
||||
let concrete = concreteType(c, a)
|
||||
let concrete = concreteType(c, a, f)
|
||||
if concrete == nil: return isNone
|
||||
put(c, f, concrete)
|
||||
# bug #6526
|
||||
@@ -1684,7 +1691,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
|
||||
a.sym.kind = skType
|
||||
a.flags.excl tfWildcard
|
||||
else:
|
||||
concrete = concreteType(c, a)
|
||||
concrete = concreteType(c, a, f)
|
||||
if concrete == nil:
|
||||
return isNone
|
||||
if doBind:
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
discard """
|
||||
cmd: "nim c --newruntime $file"
|
||||
errormsg: "sink parameter `a` is already consumed at tconsume_twice.nim(8, 6)"
|
||||
line: 10
|
||||
errormsg: "sink parameter `a` is already consumed at tconsume_twice.nim(11, 10)"
|
||||
line: 13
|
||||
"""
|
||||
type
|
||||
Foo = ref object
|
||||
|
||||
proc consumeTwice(a: owned proc()): owned proc() =
|
||||
if a == nil:
|
||||
proc use(a: owned Foo): bool = discard
|
||||
proc consumeTwice(a: owned Foo): owned Foo =
|
||||
if use(a):
|
||||
return
|
||||
return a
|
||||
|
||||
assert consumeTwice(proc() = discard) != nil
|
||||
assert consumeTwice(Foo()) != nil
|
||||
|
||||
@@ -62,6 +62,11 @@ proc main =
|
||||
|
||||
w.draw()
|
||||
|
||||
# bug #11257
|
||||
var a: owned proc()
|
||||
if a != nil:
|
||||
a()
|
||||
|
||||
main()
|
||||
|
||||
let (a, d) = allocCounters()
|
||||
|
||||
Reference in New Issue
Block a user