fixes #3452
This commit is contained in:
parent
ec2d370053
commit
9cc25f8b77
3 changed files with 41 additions and 2 deletions
|
|
@ -95,7 +95,7 @@ proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) =
|
||||||
# Gives a detailed error message; this is separated from semOverloadedCall,
|
# Gives a detailed error message; this is separated from semOverloadedCall,
|
||||||
# as semOverlodedCall is already pretty slow (and we need this information
|
# as semOverlodedCall is already pretty slow (and we need this information
|
||||||
# only in case of an error).
|
# only in case of an error).
|
||||||
if c.compilesContextId > 0:
|
if c.compilesContextId > 0 and optReportConceptFailures notin gGlobalOptions:
|
||||||
# fail fast:
|
# fail fast:
|
||||||
globalError(n.info, errTypeMismatch, "")
|
globalError(n.info, errTypeMismatch, "")
|
||||||
if errors.isNil or errors.len == 0:
|
if errors.isNil or errors.len == 0:
|
||||||
|
|
@ -133,6 +133,9 @@ proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) =
|
||||||
add(candidates, "\n")
|
add(candidates, "\n")
|
||||||
if candidates != "":
|
if candidates != "":
|
||||||
add(result, "\n" & msgKindToString(errButExpected) & "\n" & candidates)
|
add(result, "\n" & msgKindToString(errButExpected) & "\n" & candidates)
|
||||||
|
if c.compilesContextId > 0 and optReportConceptFailures in gGlobalOptions:
|
||||||
|
globalError(n.info, errGenerated, result)
|
||||||
|
else:
|
||||||
localError(n.info, errGenerated, result)
|
localError(n.info, errGenerated, result)
|
||||||
|
|
||||||
proc gatherUsedSyms(c: PContext, usedSyms: var seq[PNode]) =
|
proc gatherUsedSyms(c: PContext, usedSyms: var seq[PNode]) =
|
||||||
|
|
|
||||||
|
|
@ -684,6 +684,13 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
|
||||||
of tyAnything:
|
of tyAnything:
|
||||||
return if f.kind == tyAnything: isGeneric
|
return if f.kind == tyAnything: isGeneric
|
||||||
else: isNone
|
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, false)
|
||||||
|
if x >= isGeneric:
|
||||||
|
return isGeneric
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
case f.kind
|
case f.kind
|
||||||
|
|
|
||||||
29
tests/concepts/tgraph.nim
Normal file
29
tests/concepts/tgraph.nim
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
discard """
|
||||||
|
output: '''XY is Node
|
||||||
|
MyGraph is Graph'''
|
||||||
|
"""
|
||||||
|
# bug #3452
|
||||||
|
import math
|
||||||
|
|
||||||
|
type
|
||||||
|
Node* = concept n
|
||||||
|
`==`(n, n) is bool
|
||||||
|
|
||||||
|
Graph* = concept g
|
||||||
|
var x: Node
|
||||||
|
distance(g, x, x) is float
|
||||||
|
|
||||||
|
XY* = tuple[x, y: int]
|
||||||
|
|
||||||
|
MyGraph* = object
|
||||||
|
points: seq[XY]
|
||||||
|
|
||||||
|
if XY is Node:
|
||||||
|
echo "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) )
|
||||||
|
|
||||||
|
if MyGraph is Graph:
|
||||||
|
echo "MyGraph is Graph"
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue