Fix #5983
This commit is contained in:
parent
21ce7b2af4
commit
07d50cedf0
3 changed files with 32 additions and 1 deletions
|
|
@ -106,7 +106,10 @@ proc checkConvertible(c: PContext, castDest, src: PType): TConvStatus =
|
||||||
result = convNotNeedeed
|
result = convNotNeedeed
|
||||||
return
|
return
|
||||||
var d = skipTypes(castDest, abstractVar)
|
var d = skipTypes(castDest, abstractVar)
|
||||||
var s = skipTypes(src, abstractVar-{tyTypeDesc})
|
var s = src
|
||||||
|
if s.kind in tyUserTypeClasses and s.isResolvedUserTypeClass:
|
||||||
|
s = s.lastSon
|
||||||
|
s = skipTypes(s, abstractVar-{tyTypeDesc})
|
||||||
var pointers = 0
|
var pointers = 0
|
||||||
while (d != nil) and (d.kind in {tyPtr, tyRef}) and (d.kind == s.kind):
|
while (d != nil) and (d.kind in {tyPtr, tyRef}) and (d.kind == s.kind):
|
||||||
d = d.lastSon
|
d = d.lastSon
|
||||||
|
|
|
||||||
|
|
@ -424,6 +424,12 @@ template bindConcreteTypeToUserTypeClass*(tc, concrete: PType) =
|
||||||
tc.sons.safeAdd concrete
|
tc.sons.safeAdd concrete
|
||||||
tc.flags.incl tfResolved
|
tc.flags.incl tfResolved
|
||||||
|
|
||||||
|
# TODO: It would be a good idea to kill the special state of a resolved
|
||||||
|
# concept by switching to tyAlias within the instantiated procs.
|
||||||
|
# Currently, tyAlias is always skipped with lastSon, which means that
|
||||||
|
# we can store information about the matched concept in another position.
|
||||||
|
# Then builtInFieldAccess can be modified to properly read the derived
|
||||||
|
# consts and types stored within the concept.
|
||||||
template isResolvedUserTypeClass*(t: PType): bool =
|
template isResolvedUserTypeClass*(t: PType): bool =
|
||||||
tfResolved in t.flags
|
tfResolved in t.flags
|
||||||
|
|
||||||
|
|
|
||||||
22
tests/concepts/t5983.nim
Normal file
22
tests/concepts/t5983.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
discard """
|
||||||
|
output: "20.0 USD"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import typetraits
|
||||||
|
|
||||||
|
const currencies = ["USD", "EUR"] # in real code 120 currencies
|
||||||
|
|
||||||
|
type USD* = distinct float # in real code 120 types generates using macro
|
||||||
|
type EUR* = distinct float
|
||||||
|
|
||||||
|
type CurrencyAmount = concept c
|
||||||
|
type t = c.type
|
||||||
|
const name = c.type.name
|
||||||
|
name in currencies
|
||||||
|
|
||||||
|
proc `$`(x: CurrencyAmount): string =
|
||||||
|
$float(x) & " " & x.name
|
||||||
|
|
||||||
|
let amount = 20.USD
|
||||||
|
echo amount
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue