Fix subranges of distinct types (#18816) [backport]
This commit is contained in:
parent
30d28bcefc
commit
ee2eb5cae2
2 changed files with 15 additions and 1 deletions
|
|
@ -124,7 +124,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||||
result = typeAllowedAux(marker, lastSon(t), kind, c, flags)
|
result = typeAllowedAux(marker, lastSon(t), kind, c, flags)
|
||||||
of tyRange:
|
of tyRange:
|
||||||
if skipTypes(t[0], abstractInst-{tyTypeDesc}).kind notin
|
if skipTypes(t[0], abstractInst-{tyTypeDesc}).kind notin
|
||||||
{tyChar, tyEnum, tyInt..tyFloat128, tyInt..tyUInt64}: result = t
|
{tyChar, tyEnum, tyInt..tyFloat128, tyInt..tyUInt64, tyRange}: result = t
|
||||||
of tyOpenArray:
|
of tyOpenArray:
|
||||||
# you cannot nest openArrays/sinks/etc.
|
# you cannot nest openArrays/sinks/etc.
|
||||||
if (kind != skParam or taIsOpenArray in flags) and views notin c.features:
|
if (kind != skParam or taIsOpenArray in flags) and views notin c.features:
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,20 @@ template main() =
|
||||||
s.Foo.add('c')
|
s.Foo.add('c')
|
||||||
doAssert s.string == "c" # was failing
|
doAssert s.string == "c" # was failing
|
||||||
test()
|
test()
|
||||||
|
block: #18061
|
||||||
|
type
|
||||||
|
A = distinct (0..100)
|
||||||
|
B = A(0) .. A(10)
|
||||||
|
proc test(b: B) = discard
|
||||||
|
let
|
||||||
|
a = A(10)
|
||||||
|
b = B(a)
|
||||||
|
test(b)
|
||||||
|
|
||||||
|
proc test(a: A) = discard
|
||||||
|
discard cast[B](A(1))
|
||||||
|
var c: B
|
||||||
|
|
||||||
|
|
||||||
static: main()
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue