Skip to content

Commit

Permalink
include new concepts in typeclasses, makes containsGenericType work (#…
Browse files Browse the repository at this point in the history
…24453)

fixes #24450

The new concepts were previously not included in
[containsGenericType][1] which prevents them from being instantiated.
Here they are included by being added to `tyTypeClasses` though this
doesn't have to be done, they can also be added manually to
`containsGenericTypeIter`, but this might be too specific.

[1]:
https://github.com/nim-lang/Nim/blob/a2031ec6cfe9475fb38ebc204ebcf8c2b6d02dce/compiler/types.nim#L1507-L1517
  • Loading branch information
metagn authored Nov 19, 2024
1 parent a610f23 commit e28d2f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ const
GcTypeKinds* = {tyRef, tySequence, tyString}

tyTypeClasses* = {tyBuiltInTypeClass, tyCompositeTypeClass,
tyUserTypeClass, tyUserTypeClassInst,
tyUserTypeClass, tyUserTypeClassInst, tyConcept,
tyAnd, tyOr, tyNot, tyAnything}

tyMetaTypes* = {tyGenericParam, tyTypeDesc, tyUntyped} + tyTypeClasses
Expand Down
3 changes: 0 additions & 3 deletions compiler/typeallowed.nim
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
result = typeAllowedAux(marker, t.skipModifier, kind, c, flags+{taHeap})
else:
result = t
of tyConcept:
if kind != skParam: result = t
else: result = nil

proc typeAllowed*(t: PType, kind: TSymKind; c: PContext; flags: TTypeAllowedFlags = {}): PType =
# returns 'nil' on success and otherwise the part of the type that is
Expand Down
17 changes: 17 additions & 0 deletions tests/concepts/tuninstantiated.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
block: # issue #24450
type
B = object
b: int
A = object
x: int
AConcept = concept
proc implementation(s: var Self, p1: B)

proc implementation(r: var A, p1: B)=
discard

proc accept(r: var AConcept)=
discard

var a = A()
a.accept()

0 comments on commit e28d2f4

Please sign in to comment.