mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-28 10:13:56 +00:00
introduce a pre-processing pass for the concept bodies
fixes #4982 fixes #3805 close #3414
This commit is contained in:
committed by
Andreas Rumpf
parent
30ccadfe4c
commit
cd02561368
22
tests/concepts/t3414.nim
Normal file
22
tests/concepts/t3414.nim
Normal 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
18
tests/concepts/t4982.nim
Normal 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)
|
||||
|
||||
Reference in New Issue
Block a user