diff options
author | Jason Beetham <beefers331@gmail.com> | 2021-09-07 09:11:08 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-07 17:11:08 +0200 |
commit | ee2eb5cae2585c5cd0a476814bd5879c130e5d30 (patch) | |
tree | bec1b50ea11881c0db48f683f3d3ad66175b77eb | |
parent | 30d28bcefcad0da8900cfa231be9d77bb98c5097 (diff) | |
download | Nim-ee2eb5cae2585c5cd0a476814bd5879c130e5d30.tar.gz |
Fix subranges of distinct types (#18816) [backport]
-rw-r--r-- | compiler/typeallowed.nim | 2 | ||||
-rw-r--r-- | tests/distinct/tdistinct.nim | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/compiler/typeallowed.nim b/compiler/typeallowed.nim index 2f0c039a4..d00aa538f 100644 --- a/compiler/typeallowed.nim +++ b/compiler/typeallowed.nim @@ -124,7 +124,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, result = typeAllowedAux(marker, lastSon(t), kind, c, flags) of tyRange: 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: # you cannot nest openArrays/sinks/etc. if (kind != skParam or taIsOpenArray in flags) and views notin c.features: diff --git a/tests/distinct/tdistinct.nim b/tests/distinct/tdistinct.nim index 876975a7c..fd60b4ac0 100644 --- a/tests/distinct/tdistinct.nim +++ b/tests/distinct/tdistinct.nim @@ -167,6 +167,20 @@ template main() = s.Foo.add('c') doAssert s.string == "c" # was failing 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() main() |