introduce a pre-processing pass for the concept bodies

fixes #4982
fixes #3805

close #3414
This commit is contained in:
Zahary Karadjov
2017-06-05 05:20:13 +03:00
committed by Andreas Rumpf
parent 30ccadfe4c
commit cd02561368
13 changed files with 138 additions and 60 deletions

22
tests/concepts/t3414.nim Normal file
View File

@@ -0,0 +1,22 @@
type
View[T] = concept v
v.empty is bool
v.front is T
popFront v
proc find(view: View; target: View.T): View =
result = view
while not result.empty:
if view.front == target:
return
mixin popFront
popFront result
proc popFront[T](s: var seq[T]) = discard
proc empty[T](s: seq[T]): bool = false
var s1 = @[1, 2, 3]
let s2 = s1.find(10)

18
tests/concepts/t4982.nim Normal file
View File

@@ -0,0 +1,18 @@
discard """
errormsg: "undeclared identifier: 'x'"
line: 10
"""
import typetraits # without this import the program compiles (and echos false)
type
SomeTestConcept = concept t
x.name is string # typo: t.name was intended (which would result in echo true)
type
TestClass = ref object of RootObj
name: string
var test = TestClass(name: "mytest")
echo $(test is SomeTestConcept)