Fix #5127
This commit is contained in:
parent
8f4b374327
commit
16eb4b1fee
5 changed files with 60 additions and 32 deletions
|
|
@ -1777,7 +1777,7 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
|
|
||||||
let verdict = semConstExpr(c, n[i])
|
let verdict = semConstExpr(c, n[i])
|
||||||
if verdict.intVal == 0:
|
if verdict.intVal == 0:
|
||||||
localError(result.info, "type class predicate failed")
|
localError(result.info, "concept predicate failed")
|
||||||
of tyUnknown: continue
|
of tyUnknown: continue
|
||||||
else: discard
|
else: discard
|
||||||
if n.sons[i].typ == enforceVoidContext: #or usesResult(n.sons[i]):
|
if n.sons[i].typ == enforceVoidContext: #or usesResult(n.sons[i]):
|
||||||
|
|
|
||||||
|
|
@ -1040,11 +1040,12 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
else: isNone
|
else: isNone
|
||||||
|
|
||||||
of tyUserTypeClass, tyUserTypeClassInst:
|
of tyUserTypeClass, tyUserTypeClassInst:
|
||||||
# consider this: 'var g: Node' *within* a concept where 'Node'
|
if c.c.matchedConcept != nil:
|
||||||
# is a concept too (tgraph)
|
# consider this: 'var g: Node' *within* a concept where 'Node'
|
||||||
let x = typeRel(c, a, f, flags + {trDontBind})
|
# is a concept too (tgraph)
|
||||||
if x >= isGeneric:
|
let x = typeRel(c, a, f, flags + {trDontBind})
|
||||||
return isGeneric
|
if x >= isGeneric:
|
||||||
|
return isGeneric
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
case f.kind
|
case f.kind
|
||||||
|
|
|
||||||
|
|
@ -9,33 +9,33 @@ proc e(o: ExplainedConcept): int
|
||||||
texplain.nim(65, 6) ExplainedConcept: undeclared field: 'foo'
|
texplain.nim(65, 6) ExplainedConcept: undeclared field: 'foo'
|
||||||
texplain.nim(65, 6) ExplainedConcept: undeclared field: '.'
|
texplain.nim(65, 6) ExplainedConcept: undeclared field: '.'
|
||||||
texplain.nim(65, 6) ExplainedConcept: expression '.' cannot be called
|
texplain.nim(65, 6) ExplainedConcept: expression '.' cannot be called
|
||||||
texplain.nim(65, 5) ExplainedConcept: type class predicate failed
|
texplain.nim(65, 5) ExplainedConcept: concept predicate failed
|
||||||
texplain.nim(66, 6) ExplainedConcept: undeclared field: 'bar'
|
texplain.nim(66, 6) ExplainedConcept: undeclared field: 'bar'
|
||||||
texplain.nim(66, 6) ExplainedConcept: undeclared field: '.'
|
texplain.nim(66, 6) ExplainedConcept: undeclared field: '.'
|
||||||
texplain.nim(66, 6) ExplainedConcept: expression '.' cannot be called
|
texplain.nim(66, 6) ExplainedConcept: expression '.' cannot be called
|
||||||
texplain.nim(65, 5) ExplainedConcept: type class predicate failed
|
texplain.nim(65, 5) ExplainedConcept: concept predicate failed
|
||||||
|
|
||||||
texplain.nim(105, 10) Hint: Non-matching candidates for e(10)
|
texplain.nim(105, 10) Hint: Non-matching candidates for e(10)
|
||||||
proc e(o: ExplainedConcept): int
|
proc e(o: ExplainedConcept): int
|
||||||
texplain.nim(65, 6) ExplainedConcept: undeclared field: 'foo'
|
texplain.nim(65, 6) ExplainedConcept: undeclared field: 'foo'
|
||||||
texplain.nim(65, 6) ExplainedConcept: undeclared field: '.'
|
texplain.nim(65, 6) ExplainedConcept: undeclared field: '.'
|
||||||
texplain.nim(65, 6) ExplainedConcept: expression '.' cannot be called
|
texplain.nim(65, 6) ExplainedConcept: expression '.' cannot be called
|
||||||
texplain.nim(65, 5) ExplainedConcept: type class predicate failed
|
texplain.nim(65, 5) ExplainedConcept: concept predicate failed
|
||||||
texplain.nim(66, 6) ExplainedConcept: undeclared field: 'bar'
|
texplain.nim(66, 6) ExplainedConcept: undeclared field: 'bar'
|
||||||
texplain.nim(66, 6) ExplainedConcept: undeclared field: '.'
|
texplain.nim(66, 6) ExplainedConcept: undeclared field: '.'
|
||||||
texplain.nim(66, 6) ExplainedConcept: expression '.' cannot be called
|
texplain.nim(66, 6) ExplainedConcept: expression '.' cannot be called
|
||||||
texplain.nim(65, 5) ExplainedConcept: type class predicate failed
|
texplain.nim(65, 5) ExplainedConcept: concept predicate failed
|
||||||
|
|
||||||
texplain.nim(109, 20) Error: type mismatch: got (NonMatchingType)
|
texplain.nim(109, 20) Error: type mismatch: got (NonMatchingType)
|
||||||
but expected one of:
|
but expected one of:
|
||||||
proc e(o: ExplainedConcept): int
|
proc e(o: ExplainedConcept): int
|
||||||
texplain.nim(65, 5) ExplainedConcept: type class predicate failed
|
texplain.nim(65, 5) ExplainedConcept: concept predicate failed
|
||||||
proc e(i: int): int
|
proc e(i: int): int
|
||||||
|
|
||||||
texplain.nim(110, 20) Error: type mismatch: got (NonMatchingType)
|
texplain.nim(110, 20) Error: type mismatch: got (NonMatchingType)
|
||||||
but expected one of:
|
but expected one of:
|
||||||
proc r(o: RegularConcept): int
|
proc r(o: RegularConcept): int
|
||||||
texplain.nim(69, 5) RegularConcept: type class predicate failed
|
texplain.nim(69, 5) RegularConcept: concept predicate failed
|
||||||
proc r[T](a: SomeNumber; b: T; c: auto)
|
proc r[T](a: SomeNumber; b: T; c: auto)
|
||||||
proc r(i: string): int
|
proc r(i: string): int
|
||||||
|
|
||||||
|
|
@ -49,12 +49,12 @@ proc f(o: NestedConcept)
|
||||||
texplain.nim(69, 6) RegularConcept: undeclared field: 'foo'
|
texplain.nim(69, 6) RegularConcept: undeclared field: 'foo'
|
||||||
texplain.nim(69, 6) RegularConcept: undeclared field: '.'
|
texplain.nim(69, 6) RegularConcept: undeclared field: '.'
|
||||||
texplain.nim(69, 6) RegularConcept: expression '.' cannot be called
|
texplain.nim(69, 6) RegularConcept: expression '.' cannot be called
|
||||||
texplain.nim(69, 5) RegularConcept: type class predicate failed
|
texplain.nim(69, 5) RegularConcept: concept predicate failed
|
||||||
texplain.nim(70, 6) RegularConcept: undeclared field: 'bar'
|
texplain.nim(70, 6) RegularConcept: undeclared field: 'bar'
|
||||||
texplain.nim(70, 6) RegularConcept: undeclared field: '.'
|
texplain.nim(70, 6) RegularConcept: undeclared field: '.'
|
||||||
texplain.nim(70, 6) RegularConcept: expression '.' cannot be called
|
texplain.nim(70, 6) RegularConcept: expression '.' cannot be called
|
||||||
texplain.nim(69, 5) RegularConcept: type class predicate failed
|
texplain.nim(69, 5) RegularConcept: concept predicate failed
|
||||||
texplain.nim(73, 5) NestedConcept: type class predicate failed
|
texplain.nim(73, 5) NestedConcept: concept predicate failed
|
||||||
'''
|
'''
|
||||||
line: 119
|
line: 119
|
||||||
errormsg: "type mismatch: got (MatchingType)"
|
errormsg: "type mismatch: got (MatchingType)"
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,34 @@
|
||||||
discard """
|
|
||||||
output: '''XY is Node
|
|
||||||
MyGraph is Graph'''
|
|
||||||
"""
|
|
||||||
# bug #3452
|
# bug #3452
|
||||||
import math
|
import math
|
||||||
|
|
||||||
type
|
type
|
||||||
Node* = concept n
|
Node* = concept n
|
||||||
`==`(n, n) is bool
|
`==`(n, n) is bool
|
||||||
|
|
||||||
Graph* = concept g
|
Graph1* = concept g
|
||||||
var x: Node
|
type N = Node
|
||||||
distance(g, x, x) is float
|
distance(g, N, N) is float
|
||||||
|
|
||||||
XY* = tuple[x, y: int]
|
Graph2 = concept g
|
||||||
|
distance(g, Node, Node) is float
|
||||||
|
|
||||||
MyGraph* = object
|
Graph3 = concept g
|
||||||
points: seq[XY]
|
var x: Node
|
||||||
|
distance(g, x, x) is float
|
||||||
|
|
||||||
if XY is Node:
|
XY* = tuple[x, y: int]
|
||||||
echo "XY is Node"
|
|
||||||
|
MyGraph* = object
|
||||||
|
points: seq[XY]
|
||||||
|
|
||||||
|
static:
|
||||||
|
assert XY is Node
|
||||||
|
|
||||||
proc distance*( g: MyGraph, a, b: XY): float =
|
proc distance*( g: MyGraph, a, b: XY): float =
|
||||||
sqrt( pow(float(a.x - b.x), 2) + pow(float(a.y - b.y), 2) )
|
sqrt( pow(float(a.x - b.x), 2) + pow(float(a.y - b.y), 2) )
|
||||||
|
|
||||||
if MyGraph is Graph:
|
static:
|
||||||
echo "MyGraph is Graph"
|
assert MyGraph is Graph1
|
||||||
|
assert MyGraph is Graph2
|
||||||
|
assert MyGraph is Graph3
|
||||||
|
|
||||||
|
|
|
||||||
22
tests/concepts/twrapconcept.nim
Normal file
22
tests/concepts/twrapconcept.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "type mismatch: got (string)"
|
||||||
|
line: 21
|
||||||
|
nimout: "twrapconcept.nim(11, 5) Foo: concept predicate failed"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# https://github.com/nim-lang/Nim/issues/5127
|
||||||
|
|
||||||
|
type
|
||||||
|
Foo = concept foo
|
||||||
|
foo.get is int
|
||||||
|
|
||||||
|
FooWrap[F: Foo] = object
|
||||||
|
foo: F
|
||||||
|
|
||||||
|
proc get(x: int): int = x
|
||||||
|
|
||||||
|
proc wrap[F: Foo](foo: F): FooWrap[F] = FooWrap[F](foo: foo)
|
||||||
|
|
||||||
|
let x = wrap(12)
|
||||||
|
let y = wrap "string"
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue