mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Fix #5127
This commit is contained in:
committed by
Andreas Rumpf
parent
8f4b374327
commit
16eb4b1fee
@@ -1777,7 +1777,7 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||
|
||||
let verdict = semConstExpr(c, n[i])
|
||||
if verdict.intVal == 0:
|
||||
localError(result.info, "type class predicate failed")
|
||||
localError(result.info, "concept predicate failed")
|
||||
of tyUnknown: continue
|
||||
else: discard
|
||||
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
|
||||
|
||||
of tyUserTypeClass, tyUserTypeClassInst:
|
||||
# consider this: 'var g: Node' *within* a concept where 'Node'
|
||||
# is a concept too (tgraph)
|
||||
let x = typeRel(c, a, f, flags + {trDontBind})
|
||||
if x >= isGeneric:
|
||||
return isGeneric
|
||||
if c.c.matchedConcept != nil:
|
||||
# consider this: 'var g: Node' *within* a concept where 'Node'
|
||||
# is a concept too (tgraph)
|
||||
let x = typeRel(c, a, f, flags + {trDontBind})
|
||||
if x >= isGeneric:
|
||||
return isGeneric
|
||||
else: discard
|
||||
|
||||
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: '.'
|
||||
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: '.'
|
||||
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)
|
||||
proc e(o: ExplainedConcept): int
|
||||
texplain.nim(65, 6) ExplainedConcept: undeclared field: 'foo'
|
||||
texplain.nim(65, 6) ExplainedConcept: undeclared field: '.'
|
||||
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: '.'
|
||||
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)
|
||||
but expected one of:
|
||||
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
|
||||
|
||||
texplain.nim(110, 20) Error: type mismatch: got (NonMatchingType)
|
||||
but expected one of:
|
||||
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(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: '.'
|
||||
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: '.'
|
||||
texplain.nim(70, 6) RegularConcept: expression '.' cannot be called
|
||||
texplain.nim(69, 5) RegularConcept: type class predicate failed
|
||||
texplain.nim(73, 5) NestedConcept: type class predicate failed
|
||||
texplain.nim(69, 5) RegularConcept: concept predicate failed
|
||||
texplain.nim(73, 5) NestedConcept: concept predicate failed
|
||||
'''
|
||||
line: 119
|
||||
errormsg: "type mismatch: got (MatchingType)"
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
discard """
|
||||
output: '''XY is Node
|
||||
MyGraph is Graph'''
|
||||
"""
|
||||
# bug #3452
|
||||
import math
|
||||
|
||||
type
|
||||
Node* = concept n
|
||||
`==`(n, n) is bool
|
||||
Node* = concept n
|
||||
`==`(n, n) is bool
|
||||
|
||||
Graph* = concept g
|
||||
var x: Node
|
||||
distance(g, x, x) is float
|
||||
Graph1* = concept g
|
||||
type N = Node
|
||||
distance(g, N, N) is float
|
||||
|
||||
XY* = tuple[x, y: int]
|
||||
Graph2 = concept g
|
||||
distance(g, Node, Node) is float
|
||||
|
||||
MyGraph* = object
|
||||
points: seq[XY]
|
||||
Graph3 = concept g
|
||||
var x: Node
|
||||
distance(g, x, x) is float
|
||||
|
||||
if XY is Node:
|
||||
echo "XY is Node"
|
||||
XY* = tuple[x, y: int]
|
||||
|
||||
MyGraph* = object
|
||||
points: seq[XY]
|
||||
|
||||
static:
|
||||
assert XY is Node
|
||||
|
||||
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:
|
||||
echo "MyGraph is Graph"
|
||||
static:
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user