Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing change to concept binding #24443

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
elif x.kind == tyGenericInst and concpt.kind == tyConcept:
result = if concepts.conceptMatch(c.c, concpt, x, c.bindings, f): isGeneric
else: isNone
elif concpt.kind == tyUserTypeClass:
let inst = prepareMetatypeForSigmatch(c.c, c.bindings, c.call.info, f)
return typeRel(c, inst, a, flags)
else:
let genericBody = f[0]
var askip = skippedNone
Expand Down Expand Up @@ -1900,8 +1903,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
if aOrig == f: return isEqual
var matched = matchUserTypeClass(c, f, aOrig)
if matched != nil:
bindConcreteTypeToUserTypeClass(matched, a)
if doBind: put(c, f, matched)
if doBind: put(c, f, a)
result = isGeneric
elif a.len > 0 and a.last == f:
# Needed for checking `Y` == `Addable` in the following
Expand Down
28 changes: 28 additions & 0 deletions tests/concepts/tconcepts_concrete.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
discard """
output: '''string
A[seq[int]]
A[array[0..0, string]]
'''
"""

type
SomethingLike[T] = concept x
x.len is int
x[int] is T

A[T] = object
x: T

proc p*[T](x: SomethingLike[T]) =
echo typeof(x)

proc initA*[T; S: SomethingLike[T]](x: S): A[S] =
A[S](x: x)

proc initA2[T](x: SomethingLike[T]): auto =
A[typeof x](x:x)

p("testing")
echo typeof(initA(newSeq[int]()))
var ar: array[1, string]
echo typeof(initA2(ar))
6 changes: 2 additions & 4 deletions tests/concepts/tusertypeclasses.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ discard """
output: '''Sortable
Sortable
Container
TObj
int
oof
111 111
(id: @[1, 2, 3], name: @["Vas", "Pas", "NafNaf"], age: @[10, 16, 18])
'''
Expand Down Expand Up @@ -97,8 +96,7 @@ proc to(x: TObj, t: type string) = discard
proc to(x: TObj, t: type JSonValue) = discard

proc testFoo(x: TFoo) =
echo x.TypeName
echo x.MappedType.name
echo "oof"

testFoo(TObj(x: 10))

Expand Down
2 changes: 1 addition & 1 deletion tests/lent/t16898.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
errormsg: "invalid type: 'lent QuadraticExt' in this context: 'proc (r: var QuadraticExt, a: lent QuadraticExt, b: lent QuadraticExt){.noSideEffect, gcsafe.}' for proc"
errormsg: "invalid type: 'lent Fp2[6, system.uint64]' in this context: 'proc (r: var Fp2[6, system.uint64], a: lent Fp2[6, system.uint64], b: lent Fp2[6, system.uint64]){.noSideEffect, gcsafe.}' for proc"
"""

# bug #16898
Expand Down
Loading