mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-17 06:21:18 +00:00
hacky fix for generic constraints matching
This commit is contained in:
30
tests/reject/tgenconstraints.nim
Normal file
30
tests/reject/tgenconstraints.nim
Normal file
@@ -0,0 +1,30 @@
|
||||
discard """
|
||||
file: "tgenconstraints.nim"
|
||||
line: 25
|
||||
errormsg: "cannot instantiate T2"
|
||||
"""
|
||||
|
||||
type
|
||||
T1[T: int|string] = object
|
||||
x: T
|
||||
|
||||
T2[T: Ordinal] = object
|
||||
x: T
|
||||
|
||||
var x1: T1[int]
|
||||
var x2: T1[string]
|
||||
var x3: T2[int]
|
||||
|
||||
proc foo[T](x: T): T2[T] {.discardable.} =
|
||||
var o: T1[T]
|
||||
|
||||
foo(10)
|
||||
|
||||
proc bar(x: string|TNumber): T1[type(x)] {.discardable.} =
|
||||
when type(x) is TNumber:
|
||||
var o: T2[type(x)]
|
||||
|
||||
bar "test"
|
||||
bar 100
|
||||
bar 1.1
|
||||
|
||||
@@ -5,7 +5,7 @@ discard """
|
||||
type
|
||||
TMyTuple = tuple[a, b: int]
|
||||
|
||||
proc indexOf*(t: typedesc, name: string): int {.compiletime.} =
|
||||
proc indexOf*(t: typedesc, name: string): int =
|
||||
## takes a tuple and looks for the field by name.
|
||||
## returs index of that field.
|
||||
var
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
discard """
|
||||
file: "tfinally.nim"
|
||||
output: '''came
|
||||
here
|
||||
3'''
|
||||
output: "came\nhere\n3"
|
||||
"""
|
||||
# Test return in try statement:
|
||||
|
||||
@@ -14,10 +12,8 @@ proc main: int =
|
||||
echo("came")
|
||||
return 2
|
||||
finally:
|
||||
echo("here ")
|
||||
echo("here")
|
||||
return 3
|
||||
|
||||
|
||||
echo main() #OUT came here 3
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user