Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
Graveflo committed Nov 17, 2024
1 parent e869a95 commit dc885e5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
12 changes: 5 additions & 7 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1457,33 +1457,31 @@ proc findMetaTypeCompOrNil*(t: PType): PType=
if t == nil:
return nil
if tfHasMeta in t.flags:
return t
result = t
if t.size == szIllegalRecursion:
return nil
let tmp = t.size
t.size = szIllegalRecursion
case t.kind
of tyMetaTypes, tyNone:
result = t
result.flags.incl tfHasMeta
of tyStatic:
if t.n == nil:
result = t
result.flags.incl tfHasMeta
of tySequence, tySet, tyArray, tyOpenArray, tyVar, tyLent, tyPtr, tyRef,
tyProc, tyGenericInvocation, tyGenericInst, tyAlias, tySink, tyOwned:
let start = ord(t.kind in {tyGenericInvocation, tyGenericInst})
for i in start..<t.len:
let comp = findMetaTypeCompOrNil(t[i])
if comp != nil:
result = comp
result.flags.incl tfHasMeta
result = findMetaTypeCompOrNil(t[i])
if result != nil:
break
else:
discard
t.size = tmp

proc isMetaType*(t: PType): bool =
if tfHasMeta in t.flags:
return true
return findMetaTypeCompOrNil(t) != nil

proc genericParamHasConstraints*(t: PType): bool {.inline.} = t.sons.len > 0
Expand Down
3 changes: 1 addition & 2 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1604,8 +1604,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
# like: mydata.seq
if s.typ.kind == tyArray and s.typ.len == 2:
discard
elif s.typ.kind in {tyOpenArray, tyVarargs} and s.typ.len == 1:
# XXX investigate why `tySequence` cannot be added here for now.
elif s.typ.kind in {tyOpenArray, tyVarargs, tySequence} and s.typ.len == 1:
discard
else:
rawAddSon(s.typ, newTypeS(tyNone, c))
Expand Down
22 changes: 22 additions & 0 deletions tests/concepts/tconceptsv2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
discard """
action: "run"
output: '''
A[array[0..0, int]]
A[seq[int]]
'''
"""
type
SomethingLike[T] = concept
proc len(s: Self): int
proc `[]`(s: Self; index: int): T

A[T] = object
x: T

proc initA*(x: SomethingLike): auto =
A[type x](x: x)

var a: array[1, int]
var s: seq[int]
echo typeof(initA(a))
echo typeof(initA(s))
1 change: 1 addition & 0 deletions tests/generics/tmetafield.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
discard """
cmd: "nim check $options $file"
matrix: "--hints:off"
action: "reject"
nimout: '''
tmetafield.nim(26, 5) Error: 'proc' is not a concrete type; for a callback without parameters use 'proc()'
Expand Down

0 comments on commit dc885e5

Please sign in to comment.