This commit is contained in:
Araq
2015-10-22 12:12:05 +02:00
parent ec2d370053
commit 9cc25f8b77
3 changed files with 41 additions and 2 deletions

View File

@@ -95,7 +95,7 @@ proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) =
# Gives a detailed error message; this is separated from semOverloadedCall,
# as semOverlodedCall is already pretty slow (and we need this information
# only in case of an error).
if c.compilesContextId > 0:
if c.compilesContextId > 0 and optReportConceptFailures notin gGlobalOptions:
# fail fast:
globalError(n.info, errTypeMismatch, "")
if errors.isNil or errors.len == 0:
@@ -133,7 +133,10 @@ proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) =
add(candidates, "\n")
if candidates != "":
add(result, "\n" & msgKindToString(errButExpected) & "\n" & candidates)
localError(n.info, errGenerated, result)
if c.compilesContextId > 0 and optReportConceptFailures in gGlobalOptions:
globalError(n.info, errGenerated, result)
else:
localError(n.info, errGenerated, result)
proc gatherUsedSyms(c: PContext, usedSyms: var seq[PNode]) =
for scope in walkScopes(c.currentScope):

View File

@@ -684,6 +684,13 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
of tyAnything:
return if f.kind == tyAnything: isGeneric
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
case f.kind

29
tests/concepts/tgraph.nim Normal file
View 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"