fix assignment to converted concept type (#15051)
* fix assignment to converted concept type * check for resolved concepts * add extra test
This commit is contained in:
parent
4b93c61f0d
commit
add003a074
2 changed files with 41 additions and 17 deletions
|
|
@ -1070,7 +1070,11 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
|
|
||||||
if x == y: return true
|
if x == y: return true
|
||||||
var a = skipTypes(x, {tyGenericInst, tyAlias})
|
var a = skipTypes(x, {tyGenericInst, tyAlias})
|
||||||
|
while a.kind == tyUserTypeClass and tfResolved in a.flags:
|
||||||
|
a = skipTypes(a[^1], {tyGenericInst, tyAlias})
|
||||||
var b = skipTypes(y, {tyGenericInst, tyAlias})
|
var b = skipTypes(y, {tyGenericInst, tyAlias})
|
||||||
|
while b.kind == tyUserTypeClass and tfResolved in b.flags:
|
||||||
|
b = skipTypes(b[^1], {tyGenericInst, tyAlias})
|
||||||
assert(a != nil)
|
assert(a != nil)
|
||||||
assert(b != nil)
|
assert(b != nil)
|
||||||
if a.kind != b.kind:
|
if a.kind != b.kind:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
type
|
block:
|
||||||
|
type
|
||||||
hasFieldX = concept z
|
hasFieldX = concept z
|
||||||
z.x is int
|
z.x is int
|
||||||
|
|
||||||
|
|
@ -13,12 +14,31 @@ type
|
||||||
p_o_x = ptr obj_x
|
p_o_x = ptr obj_x
|
||||||
v_o_x = var obj_x
|
v_o_x = var obj_x
|
||||||
|
|
||||||
template check(x) =
|
template check(x) =
|
||||||
static: assert(x)
|
static: assert(x)
|
||||||
|
|
||||||
check obj_x is hasFieldX
|
check obj_x is hasFieldX
|
||||||
check ref_obj_x is hasFieldX
|
check ref_obj_x is hasFieldX
|
||||||
check ref_to_obj_x is hasFieldX
|
check ref_to_obj_x is hasFieldX
|
||||||
check p_o_x is hasFieldX
|
check p_o_x is hasFieldX
|
||||||
check v_o_x is hasFieldX
|
check v_o_x is hasFieldX
|
||||||
|
|
||||||
|
block:
|
||||||
|
type
|
||||||
|
Foo = concept x
|
||||||
|
x.isFoo
|
||||||
|
Bar = distinct float
|
||||||
|
template isFoo(x: Bar): untyped = true
|
||||||
|
proc foo(x: var Foo) =
|
||||||
|
float(x) = 1.0
|
||||||
|
proc foo2(x: var Bar) =
|
||||||
|
float(x) = 1.0
|
||||||
|
proc foo3(x: var (Bar|SomeNumber)) =
|
||||||
|
float(x) = 1.0
|
||||||
|
proc foo4(x: var any) =
|
||||||
|
float(x) = 1.0
|
||||||
|
var x: Bar
|
||||||
|
foo(x)
|
||||||
|
foo2(x)
|
||||||
|
foo3(x)
|
||||||
|
foo4(x)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue