fixes #7600, generic object with generic ref object parent typerel bug (#7678)

* fixes #7600

* fix wrong logic
This commit is contained in:
andri lim
2018-04-27 13:53:20 +07:00
committed by Andreas Rumpf
parent 397e173139
commit e4aa140d22
3 changed files with 42 additions and 2 deletions

View File

@@ -1388,8 +1388,13 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
var aAsObject = roota.lastSon
if fKind in {tyRef, tyPtr} and aAsObject.kind == fKind:
aAsObject = aAsObject.base
if fKind in {tyRef, tyPtr}:
if aAsObject.kind == tyObject:
# bug #7600, tyObject cannot be passed
# as argument to tyRef/tyPtr
return isNone
elif aAsObject.kind == fKind:
aAsObject = aAsObject.base
if aAsObject.kind == tyObject:
let baseType = aAsObject.base

18
tests/typerel/t7600_1.nim Normal file
View File

@@ -0,0 +1,18 @@
discard """
errormsg: "type mismatch: got <Thin[system.int]>"
nimout: '''t7600_1.nim(18, 6) Error: type mismatch: got <Thin[system.int]>
but expected one of:
proc test[T](x: Paper[T])
expression: test tn'''
"""
type
Paper[T] = ref object of RootObj
thickness: T
Thin[T] = object of Paper[T]
proc test[T](x: Paper[T]) = discard
var tn = Thin[int]()
test tn

17
tests/typerel/t7600_2.nim Normal file
View File

@@ -0,0 +1,17 @@
discard """
errormsg: "type mismatch: got <Thin>"
nimout: '''t7600_2.nim(17, 6) Error: type mismatch: got <Thin>
but expected one of:
proc test(x: Paper)
expression: test tn'''
"""
type
Paper = ref object of RootObj
Thin = object of Paper
proc test(x: Paper) = discard
var tn = Thin()
test tn