This is a temporary fix that will be reworked in a follow up commit
that aims to eliminate the tfExplicit flag from the compiler. The
complete and proper fix was considered too risky for inclusion just
before our 0.19 release.
This commit is contained in:
zah 2018-08-21 23:14:12 +03:00 • committed by Andreas Rumpf
commit 96de224a63
5 changed files with 20 additions and 2 deletions

View file

@ -506,6 +506,7 @@ type
tfGenericTypeParam tfGenericTypeParam
tfImplicitTypeParam tfImplicitTypeParam
tfInferrableStatic tfInferrableStatic
tfConceptMatchedTypeSym
tfExplicit # for typedescs, marks types explicitly prefixed with the tfExplicit # for typedescs, marks types explicitly prefixed with the
# `type` operator (e.g. type int) # `type` operator (e.g. type int)
tfWildcard # consider a proc like foo[T, I](x: Type[T, I]) tfWildcard # consider a proc like foo[T, I](x: Type[T, I])

View file

@ -1342,7 +1342,7 @@ proc semTypeClass(c: PContext, n: PNode, prev: PType): PType =
if modifier != tyNone: if modifier != tyNone:
dummyName = param[0] dummyName = param[0]
dummyType = c.makeTypeWithModifier(modifier, candidateTypeSlot) dummyType = c.makeTypeWithModifier(modifier, candidateTypeSlot)
if modifier == tyTypeDesc: dummyType.flags.incl tfExplicit if modifier == tyTypeDesc: dummyType.flags.incl tfConceptMatchedTypeSym
else: else:
dummyName = param dummyName = param
dummyType = candidateTypeSlot dummyType = candidateTypeSlot

View file

@ -993,7 +993,8 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
useTypeLoweringRuleInTypeClass = c.c.matchedConcept != nil and useTypeLoweringRuleInTypeClass = c.c.matchedConcept != nil and
not c.isNoCall and not c.isNoCall and
f.kind != tyTypeDesc and f.kind != tyTypeDesc and
tfExplicit notin aOrig.flags tfExplicit notin aOrig.flags and
tfConceptMatchedTypeSym notin aOrig.flags
aOrig = if useTypeLoweringRuleInTypeClass: aOrig = if useTypeLoweringRuleInTypeClass:
aOrig.skipTypes({tyTypeDesc}) aOrig.skipTypes({tyTypeDesc})

View file

@ -11,3 +11,15 @@ type Monoid = concept x, y
proc z(x: typedesc[int]): int = 0 proc z(x: typedesc[int]): int = 0
echo(int is Monoid) echo(int is Monoid)
# https://github.com/nim-lang/Nim/issues/8126
type AdditiveMonoid* = concept x, y, type T
x + y is T
# some redundant checks to test an alternative approaches:
type TT = type(x)
x + y is type(x)
x + y is TT
doAssert(1 is AdditiveMonoid)

View file

@ -40,3 +40,7 @@ static:
assert y isnot tuple assert y isnot tuple
assert z isnot seq assert z isnot seq
# XXX: These cases don't work properly at the moment:
# assert type[int] isnot int
# assert type(int) isnot int