Skip to content

Commit

Permalink
test case haul to prevent pileup (#24525)
Browse files Browse the repository at this point in the history
closes #6013, closes #7009, closes #9190, closes #12487, closes #12831,
closes #13184, closes #13252, closes #14860, closes #14877, closes
#14894, closes #14917, closes #16153, closes #16439, closes #17779,
closes #18074, closes #18202, closes #18314, closes #18648, closes
#19063, closes #19446, closes #20065, closes #20367, closes #22126,
closes #22820, closes #22888, closes #23020, closes #23287, closes
#23510
  • Loading branch information
metagn authored Dec 9, 2024
1 parent d408b94 commit aeb3fe9
Show file tree
Hide file tree
Showing 27 changed files with 393 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/array/tgenericindex.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
block: # issue #13184
type
TypeClass = uint | enum | int
ArrayAlias[I: TypeClass] = array[I, int]

proc test[I: TypeClass](points: ArrayAlias[I]) =
discard
15 changes: 15 additions & 0 deletions tests/cpp/timportedtypecrash.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
discard """
action: compile
targets: "cpp"
matrix: "--compileOnly"
"""

# issue #20065

type
Foo* {.importC, nodecl.} = object # doesn't matter if this is importC or importCpp
value*: int64
Bar* {.importCpp, nodecl.} = object # no segfault with importC
foo*: Foo

discard @[Bar()]
1 change: 1 addition & 0 deletions tests/errmsgs/mambtype1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Y* = object
1 change: 1 addition & 0 deletions tests/errmsgs/mambtype2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Y* = object
14 changes: 14 additions & 0 deletions tests/errmsgs/tambtype.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# issue #23510

import ./mambtype1
import ./mambtype2

proc u(d: int | int) =
var r: Y #[tt.Error
^ ambiguous identifier: 'Y' -- use one of the following:
mambtype1.Y: Y
mambtype2.Y: Y]#
static: doAssert r is j.Y # because j is imported first
doAssert r is j.Y

u(0)
6 changes: 6 additions & 0 deletions tests/errmsgs/ttemplateaslambda.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# issue #16439

import std/[strutils, sequtils]
var data = "aaa aaa"
echo data.split(" ").map(toSeq) #[tt.Error
^ type mismatch: got <seq[string], template (iter: untyped): untyped>]#
47 changes: 47 additions & 0 deletions tests/generics/ttemplateparamcall.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
discard """
output: '''
L
L
L
L
B
B
B
B
'''
"""

# issue #18202

type
R = object
S = object
U = R | S

L = object
B = object
C = B | L

proc f(n: L, q: R | S) = echo "L"
proc f(n: B, q: R | S) = echo "B"

proc g(n: C, q: R | S) = echo (when n is L: "L" else: "B")

proc h(n: L, q: U) = echo "L"
proc h(n: B, q: U) = echo "B"

proc j(n: C, q: U) = echo (when n is L: "L" else: "B")

proc e(n: B | L, a: R) =
template t(operations: untyped, fn: untyped) = fn(n, operations)

# Work as expected
t(a, f)
t(a, g)
t(a, j)

# Error: type mismatch: got <R, proc [*missing parameters*](n: B, q: U) | proc [*missing parameters*](n: L, q: U)>
t(a, h)

e(L(), R())
e(B(), R())
39 changes: 39 additions & 0 deletions tests/generics/tuninstantiatedgenericcalls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ block: # issue #15959
my3(x, x)
doAssert not compiles(my3(x, x[0]))

block: # issue #14877
proc fn[T](a: T, index: int): typeof(a.x) = a.x # ok
proc fn2(a: seq[int], index: int): typeof(a[0]) = a[index] # ok
proc fn3[T](a: T, index: int): typeof(a[0]) = a[index] # Error: type mismatch: got <T, int literal(0)>

block: # issue #22342, type section version of #22607
type GenAlias[isInt: static bool] = (
when isInt:
Expand Down Expand Up @@ -515,3 +520,37 @@ block: # issue #16175
var s = Thing[1]()
doAssert s.kid is Thing[0.uint]
doAssert s.kid.kid is char

block: # issue #23287
template emitTupleType(trait: typedesc): untyped =
trait

type
Traitor[Traits] = ref object of RootObj ##
vtable: emitTupleType(Traits)

type Generic[X] = object

proc test2[Traits](val: Traitor[Generic[Traits]]) =
static: assert val.vtable is Generic[int]

proc test[X](val: Traitor[Generic[X]]) = discard

test2 Traitor[Generic[int]]() # This should error, but passes
test Traitor[Generic[int]]()

block: # issue #20367, example 1
template someTemp(T:type):typedesc = T
type
Foo[T2] = someTemp(T2)
Bar[T1] = Foo[T1]
var u:Foo[float] # works
var v:Bar[float] # Error: invalid type: 'None' in this context: 'Bar[system.float]' for var

block: # issue #20367, example 2
template someOtherTemp(p:static[int]):untyped = array[p,int]
type
Foo2[n:static[int]] = someOtherTemp(n)
Bar2[m:static[int]] = Foo2[m]
var x:Foo2[1] # works
var y:Bar2[1] # Error: undeclared identifier: 'n'
19 changes: 19 additions & 0 deletions tests/iter/tnestedclosures.nim
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,22 @@ block: #3824
echo x

main()

block: # issue #12487
iterator FaiReader(): string {.closure.} =
yield "something"

template toClosure(i): auto =
iterator j: string {.closure.} =
for x in FaiReader():
yield x
j

proc main =
var reader = toClosure(FaiReader())
var s: seq[string] = @[]
for x in reader():
s.add(x)
doAssert s == @["something"]

main()
10 changes: 10 additions & 0 deletions tests/iter/tsubscript.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# issue #14860

type
Dummie = object

iterator `[]`(d: Dummie, a, b: int): int = discard

let d = Dummie()

for s in d[0, 1]: discard # error here
6 changes: 6 additions & 0 deletions tests/lexer/titerwrongexport.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# issue #19063

iterator items[T]*(s: seq[T]): T = #[tt.Error
^ invalid indentation; an export marker '*' follows the declared identifier]#
for i in system.items(s):
yield i
18 changes: 18 additions & 0 deletions tests/macros/ttypedsymchoice.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# issue #12831

import std/[macros, strutils]

macro dumpRepr(x: typed): untyped =
result = newLit(x.treeRepr & "\n")
doAssert dumpRepr(`$`).startsWith("ClosedSymChoice")

# issue #19446

macro typedVarargs(x: varargs[typed]): untyped =
result = newLit($x[0].kind)

macro typedSingle(x: typed): untyped =
result = newLit($x.kind)

doAssert typedSingle(len) == "nnkClosedSymChoice"
doAssert typedVarargs(len) == "nnkClosedSymChoice"
11 changes: 11 additions & 0 deletions tests/overload/tsubtypegenericconstraint.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
block: # issue #18314
type
A = ref object of RootObj
B = ref object of A
C = ref object of B

proc foo[T: A](a: T): string = "got A"
proc foo[T: B](b: T): string = "got B"

var c = C()
doAssert foo(c) == "got B"
8 changes: 8 additions & 0 deletions tests/proc/msugarcrash1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import std/options

type
Address* = object
port*: int

Node* = ref object
address*: Option[Address]
6 changes: 6 additions & 0 deletions tests/proc/tdefaultprocparam.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ proc foo(a = 0, b = a.high, c = high(typeof(a))) =

foo()

import std/strformat

block: # issue #18074
proc somefn[T](query: string, _: type[T], message = query) = discard
somefn(fmt"", string)

10 changes: 10 additions & 0 deletions tests/proc/tdefaultvalueconv.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# issue #22126

func foo[T](arr: openArray[T], idx: Natural = arr.high): int = # missed conversion: `Natural(arr.high)`
if idx == 0:
return 0
foo(arr, idx - 1)

let arr = [0, 1, 2]

doAssert foo(arr) == 0
14 changes: 14 additions & 0 deletions tests/proc/texplicitgenericconstraint.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# issue #23020

proc n[T: bool](k: int | int) =
#static:
# doAssert T is bool
# doAssert T isnot int

# And runtime
block:
doAssert T is bool
doAssert T isnot int

n[int](0) #[tt.Error
^ type mismatch: got <int literal(0)>]#
16 changes: 16 additions & 0 deletions tests/proc/texplicitgenerics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,19 @@ block: # explicit generic with unresolved generic param, https://forum.nim-lang.
var x = [1, 1]
discard MyMedian(x) # emits "1\n"
doAssert s == @["1"]

block: # issue #16153
type
X[T] = openArray[T] | varargs[T] | seq[T]
Y[T] = ref object
dll: T

proc initY[T](): Y[T] =
new(result)

proc initY[T](v: X[T]): Y[T] =
new(result)
for e in v:
echo e

var deque: Y[int] = initY[int]()
22 changes: 22 additions & 0 deletions tests/proc/tstaticsignature.nim
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ block: # issue #7008
explicitGenericProc1(n, 5) # works
explicitGenericProc2(n, 5) # doesn't

block: # issue #7009
type Node[T] = object
val: T

proc genericProc(s: Node; key: s.T) =
discard # body doesn't matter
proc explicitGenericProc[T](s: Node[T]; key: T) =
discard # body doesn't matter
proc concreteProc(s: Node[cstring]; key: s.T) =
discard # body doesn't matter

var strs: Node[cstring]
concreteProc(strs, "string") # string converts to cstring
explicitGenericProc(strs, "string") # still converts
genericProc(strs, "string") # doesn't convert: COMPILE ERROR

block: # issue #20027
block:
type Test[T] = object
Expand Down Expand Up @@ -266,3 +282,9 @@ block: # issue #22276
a = x * 2)
doAssert a == 18
foo(B, proc (x: float) = doAssert x == 9)

block: # issue #9190
func foo[T, U]: type(T.low + U.low) =
T.low + U.low

doAssert foo[uint8, uint8]() == uint8.low
13 changes: 13 additions & 0 deletions tests/proc/tsugarcrash1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# issue #22820

{.push raises: [].}

import
"."/[msugarcrash1]

import
std/[options, sugar]

var closestNodes: seq[Node]
for cn in closestNodes:
discard cn.address.map(a => a.port)
7 changes: 7 additions & 0 deletions tests/proc/twrongdefaultvalue2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# issue #22888

proc dummy*[T: SomeNumber](a: T, b: T = 2.5): T = #[tt.Error
^ type mismatch: got <float64> but expected 'int']#
result = a

echo dummy(2)
12 changes: 12 additions & 0 deletions tests/range/tintypeclass.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
block: # issue #6013
type
n16 = range[0'i16..high(int16)]
SomeObj = ref object

proc doSomethingMore(idOrObj: n16 or SomeObj) =
discard

proc doSomething(idOrObj: n16 or SomeObj) =
doSomethingMore(idOrObj) # Error: type mismatch: got (int16)

doSomething(0.n16)
17 changes: 17 additions & 0 deletions tests/specialops/tmismatch.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# issue #17779

{.experimental: "dotOperators".}

type
Flag = enum
A

Flags = set[Flag]

template `.=`*(flags: Flags, key: Flag, val: bool) =
if val: flags.incl key else: flags.excl key

var flags: Flags

flags.A = 123 #[tt.Error
^ undeclared field: 'A=' for type tmismatch.Flags [type declared in tmismatch.nim(9, 5)]]#
7 changes: 7 additions & 0 deletions tests/template/mdotcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ macro bindmeQuote*(): untyped =
var ss = newStringStream("anothertext")
ss.writeData(tst[0].addr, 2)
discard ss.readData(tst[0].addr, 2) # <= comment this out to make compilation successful

# issue #14894

proc myProc(s: string) = discard

template myTemplate* =
"".myProc
3 changes: 3 additions & 0 deletions tests/template/tdotcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ block: # issue #7889
bindmeQuote()
if false:
bindmeTemplate()

block: # issue #14894
myTemplate()
Loading

0 comments on commit aeb3fe9

Please sign in to comment.