From 9cc25f8b772905fcfdbdb7f059458083d177bb51 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 22 Oct 2015 12:12:05 +0200 Subject: [PATCH] fixes #3452 --- compiler/semcall.nim | 7 +++++-- compiler/sigmatch.nim | 7 +++++++ tests/concepts/tgraph.nim | 29 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tests/concepts/tgraph.nim diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 3810935318..d8838e347f 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -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): diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 642f50330e..9fda8c860b 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -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 diff --git a/tests/concepts/tgraph.nim b/tests/concepts/tgraph.nim new file mode 100644 index 0000000000..a0177a0430 --- /dev/null +++ b/tests/concepts/tgraph.nim @@ -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" +