diff options
Diffstat (limited to 'tests/reject')
34 files changed, 327 insertions, 0 deletions
diff --git a/tests/reject/99bottles.nim b/tests/reject/99bottles.nim new file mode 100644 index 000000000..14904ac0f --- /dev/null +++ b/tests/reject/99bottles.nim @@ -0,0 +1 @@ +# Test if the compiler detects invalid module names diff --git a/tests/reject/t99bott.nim b/tests/reject/t99bott.nim new file mode 100644 index 000000000..4dfb11701 --- /dev/null +++ b/tests/reject/t99bott.nim @@ -0,0 +1,28 @@ +## 99 Bottles of Beer +## http://www.99-bottles-of-beer.net/ +## Nimrod version + +## Author: Philippe Lhoste <PhiLho(a)GMX.net> http://Phi.Lho.free.fr +# 2009-11-25 +# Loosely based on my old Lua version... Updated to current official lyrics. + +proc GetBottleNumber(n: int): string = + var bs: string + if n == 0: + bs = "No more bottles" + elif n == 1: + bs = "1 bottle" + else: + bs = $n & " bottles" + return bs & " of beer" + +for bn in countdown(99, 1): + const cur = GetBottleNumber(bn) #ERROR_MSG constant expression expected + echo(cur, " on the wall, ", cur, ".") + echo("Take one down and pass it around, ", GetBottleNumber(bn-1), + " on the wall.\n") + +echo "No more bottles of beer on the wall, no more bottles of beer." +echo "Go to the store and buy some more, 99 bottles of beer on the wall." + + diff --git a/tests/reject/tadrdisc.nim b/tests/reject/tadrdisc.nim new file mode 100644 index 000000000..a7118455f --- /dev/null +++ b/tests/reject/tadrdisc.nim @@ -0,0 +1,16 @@ +# Test that the address of a dicriminants cannot be taken + +type + TKind = enum ka, kb, kc + TA = object + case k: TKind + of ka: x, y: int + of kb: a, b: string + of kc: c, d: float + +proc setKind(k: var TKind) = + k = kc + +var a: TA +setKind(a.k) #ERROR_MSG for a 'var' type a variable needs to be passed + diff --git a/tests/reject/tambsym.nim b/tests/reject/tambsym.nim new file mode 100644 index 000000000..b8eae3ba3 --- /dev/null +++ b/tests/reject/tambsym.nim @@ -0,0 +1,8 @@ +# Test ambiguous symbols + +import mambsym1, mambsym2 + +var + v: TExport #ERROR_MSG ambiguous identifier + +v = y diff --git a/tests/reject/tambsym3.nim b/tests/reject/tambsym3.nim new file mode 100644 index 000000000..96a5098c9 --- /dev/null +++ b/tests/reject/tambsym3.nim @@ -0,0 +1,8 @@ +# Test ambiguous symbols + +import mambsym1, times + +var + v = mDec #ERROR_MSG ambiguous identifier + +writeln(stdout, ord(v)) diff --git a/tests/reject/tbind2.nim b/tests/reject/tbind2.nim new file mode 100644 index 000000000..41711083f --- /dev/null +++ b/tests/reject/tbind2.nim @@ -0,0 +1,10 @@ +# Test the new ``bind`` keyword for templates + +proc p1(x: int8, y: int): int = return x + y +proc p1(x: int, y: int8): int = return x - y + +template tempBind(x, y: expr): expr = + bind p1(x, y) #ERROR_MSG ambiguous call + +echo tempBind(1'i8, 2'i8) + diff --git a/tests/reject/tbind4.nim b/tests/reject/tbind4.nim new file mode 100644 index 000000000..d0b5fc062 --- /dev/null +++ b/tests/reject/tbind4.nim @@ -0,0 +1,6 @@ +# Module B +import mbind4 + +echo genId() #ERROR_MSG instantiation from here + + diff --git a/tests/reject/tblock1.nim b/tests/reject/tblock1.nim new file mode 100644 index 000000000..0bea7ae7f --- /dev/null +++ b/tests/reject/tblock1.nim @@ -0,0 +1,11 @@ +# check for forward label and +# for failure when label is not declared + +proc main = + block endLess: + write(stdout, "Muaahh!\N") + break endLess + + break ha #ERROR + +main() diff --git a/tests/reject/tconstr1.nim b/tests/reject/tconstr1.nim new file mode 100644 index 000000000..488170350 --- /dev/null +++ b/tests/reject/tconstr1.nim @@ -0,0 +1,23 @@ +# Test array, record constructors + +type + TComplexRecord = tuple[ + s: string, + x, y: int, + z: float, + chars: set[Char]] + +proc testSem = + var + things: array [0..1, TComplexRecord] = [ + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})] + write(stdout, things[0].x) + +const + things: array [0..1, TComplexRecord] = [ + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0)] #ERROR + otherThings = [ # the same + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})] diff --git a/tests/reject/tillrec.nim b/tests/reject/tillrec.nim new file mode 100644 index 000000000..21ce19889 --- /dev/null +++ b/tests/reject/tillrec.nim @@ -0,0 +1,10 @@ +# test illegal recursive types + +type + TLegal {.final.} = object + x: int + kids: seq[TLegal] + + TIllegal {.final.} = object #ERROR_MSG illegal recursion in type 'TIllegal' + y: Int + x: array[0..3, TIllegal] diff --git a/tests/reject/tinout.nim b/tests/reject/tinout.nim new file mode 100644 index 000000000..b4fe2fb10 --- /dev/null +++ b/tests/reject/tinout.nim @@ -0,0 +1,9 @@ +# Test in out checking for parameters + +proc abc(x: var int) = + x = 0 + +proc b() = + abc(3) #ERROR + +b() diff --git a/tests/reject/tinvalidnewseq.nim b/tests/reject/tinvalidnewseq.nim new file mode 100644 index 000000000..e2a3736c3 --- /dev/null +++ b/tests/reject/tinvalidnewseq.nim @@ -0,0 +1,20 @@ +import regexprs, strutils + +type + TURL = tuple[protocol, subdomain, domain, port: string, path: seq[string]] + +proc parseURL(url: string): TURL = + #([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)? + var pattern: string = r"([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?" + var m: array[0..6, string] #Array with the matches + newSeq(m, 7) #ERROR + discard regexprs.match(url, pattern, m) + + result = (protocol: m[1], subdomain: m[2], domain: m[3] & m[4], + port: m[5], path: m[6].split('/')) + +var r: TUrl + +r = parseUrl(r"http://google.com/search?var=bleahdhsad") +echo(r.domain) + diff --git a/tests/reject/tinvwhen.nim b/tests/reject/tinvwhen.nim new file mode 100644 index 000000000..8dc8cbf50 --- /dev/null +++ b/tests/reject/tinvwhen.nim @@ -0,0 +1,8 @@ +# This was parsed even though it should not! + +proc chdir(path: CString): cint {.importc: "chdir", header: "dirHeader".} + +proc getcwd(buf: CString, buflen: cint): CString + when defined(unix): {.importc: "getcwd", header: "<unistd.h>".} #ERROR_MSG invalid indentation + elif defined(windows): {.importc: "getcwd", header: "<direct.h>"} + else: {.error: "os library not ported to your OS. Please help!".} diff --git a/tests/reject/titer4.nim b/tests/reject/titer4.nim new file mode 100644 index 000000000..376522482 --- /dev/null +++ b/tests/reject/titer4.nim @@ -0,0 +1,3 @@ + +for x in {'a'..'z'}: #ERROR_MSG iterator within for loop context expected + nil diff --git a/tests/reject/tnamspc.nim b/tests/reject/tnamspc.nim new file mode 100644 index 000000000..eddaacfd8 --- /dev/null +++ b/tests/reject/tnamspc.nim @@ -0,0 +1,5 @@ +# Test17 - test correct handling of namespaces + +import mnamspc1 + +global = 9 #ERROR diff --git a/tests/reject/tnoop.nim b/tests/reject/tnoop.nim new file mode 100644 index 000000000..d097553e8 --- /dev/null +++ b/tests/reject/tnoop.nim @@ -0,0 +1,6 @@ +# Tests the new check in the semantic pass + +var + a: int + +a() #ERROR_MSG expression 'a()' cannot be called diff --git a/tests/reject/tnot.nim b/tests/reject/tnot.nim new file mode 100644 index 000000000..cda551654 --- /dev/null +++ b/tests/reject/tnot.nim @@ -0,0 +1,15 @@ +# BUG: following compiles, but should not: + +proc nodeOfDegree(x: Int): bool = + result = false + +proc main = + for j in 0..2: + for i in 0..10: + if not nodeOfDegree(1) >= 0: #ERROR_MSG type mismatch + Echo "Yes" + else: + Echo "No" + +main() + diff --git a/tests/reject/topaque.nim b/tests/reject/topaque.nim new file mode 100644 index 000000000..7553a749e --- /dev/null +++ b/tests/reject/topaque.nim @@ -0,0 +1,11 @@ +# Test the new opaque types + +import + mopaque + +var + L: TLexer + +L.filename = "ha" +L.line = 34 +L.buffer[0] = '\0' #ERROR_MSG undeclared field: 'buffer' diff --git a/tests/reject/topena1.nim b/tests/reject/topena1.nim new file mode 100644 index 000000000..7351edf55 --- /dev/null +++ b/tests/reject/topena1.nim @@ -0,0 +1,5 @@ +# Tests a special bug + +var + x: ref openarray[string] #ERROR_MSG invalid type + diff --git a/tests/reject/toverl.nim b/tests/reject/toverl.nim new file mode 100644 index 000000000..94f251cac --- /dev/null +++ b/tests/reject/toverl.nim @@ -0,0 +1,6 @@ +# Test for overloading + +type + TNone {.exportc: "_NONE", final.} = object + +proc TNone(a, b: int) = nil #ERROR_MSG attempt to redefine 'TNone' diff --git a/tests/reject/trawstr.nim b/tests/reject/trawstr.nim new file mode 100644 index 000000000..7b2db0335 --- /dev/null +++ b/tests/reject/trawstr.nim @@ -0,0 +1,5 @@ +# Test the new raw strings: + +const + xxx = r"This is a raw string!" + yyy = "This not\" #ERROR diff --git a/tests/reject/trecinca.nim b/tests/reject/trecinca.nim new file mode 100644 index 000000000..d78fee233 --- /dev/null +++ b/tests/reject/trecinca.nim @@ -0,0 +1,5 @@ +# Test recursive includes + +include trecincb #ERROR_MSG recursive dependency: 'tests/trecincb.nim' + +echo "trecina" diff --git a/tests/reject/trecincb.nim b/tests/reject/trecincb.nim new file mode 100644 index 000000000..6191671a1 --- /dev/null +++ b/tests/reject/trecincb.nim @@ -0,0 +1,6 @@ +# Test recursive includes + + +include trecincb #ERROR_MSG recursive dependency: 'tests/trecincb.nim' + +echo "trecinb" diff --git a/tests/reject/treciter.nim b/tests/reject/treciter.nim new file mode 100644 index 000000000..662239285 --- /dev/null +++ b/tests/reject/treciter.nim @@ -0,0 +1,7 @@ +# Test that an error message occurs for a recursive iterator + +iterator myrec(n: int): int = + for x in myrec(n-1): #ERROR_MSG recursive dependency: 'myrec' + yield x + +for x in myrec(10): echo x diff --git a/tests/reject/trectype.nim b/tests/reject/trectype.nim new file mode 100644 index 000000000..a7a6f56e0 --- /dev/null +++ b/tests/reject/trectype.nim @@ -0,0 +1,21 @@ +# Test recursive type descriptions +# (mainly for the C code generator) + +type + PA = ref TA + TA = array [0..2, PA] + + PRec = ref TRec + TRec {.final.} = object + a, b: TA + + P1 = ref T1 + PB = ref TB + TB = array [0..3, P1] + T1 = array [0..6, PB] + +var + x: PA +new(x) +#ERROR_MSG internal error: cannot generate C type for: PA + diff --git a/tests/reject/trefs.nim b/tests/reject/trefs.nim new file mode 100644 index 000000000..ab3934088 --- /dev/null +++ b/tests/reject/trefs.nim @@ -0,0 +1,16 @@ +# test for ref types (including refs to procs) + +type + TProc = proc (a, b: int): int {.stdcall.} + +proc foo(c, d: int): int {.stdcall.} = + return 0 + +proc wrongfoo(c, e: int): int {.inline.} = + return 0 + +var p: TProc +p = foo +write(stdout, "success!") +p = wrongfoo #ERROR_MSG type mismatch + diff --git a/tests/reject/tsidee1.nim b/tests/reject/tsidee1.nim new file mode 100644 index 000000000..3bd520680 --- /dev/null +++ b/tests/reject/tsidee1.nim @@ -0,0 +1,11 @@ + +var + global: int + +proc dontcare(x: int): int = return x + global + +proc SideEffectLyer(x, y: int): int {.noSideEffect.} = #ERROR_MSG 'SideEffectLyer' can have side effects + return x + y + dontcare(x) + +echo SideEffectLyer(1, 3) + diff --git a/tests/reject/tsidee4.nim b/tests/reject/tsidee4.nim new file mode 100644 index 000000000..55c474d10 --- /dev/null +++ b/tests/reject/tsidee4.nim @@ -0,0 +1,10 @@ + +var + global: int + +proc dontcare(x: int): int = return x + +proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = + return x + y + dontcare(x) + +echo noSideEffect(1, 3, dontcare) #ERROR_MSG type mismatch diff --git a/tests/reject/tsimtych.nim b/tests/reject/tsimtych.nim new file mode 100644 index 000000000..b100c62e3 --- /dev/null +++ b/tests/reject/tsimtych.nim @@ -0,0 +1,5 @@ +# Test 2 +# Simple type checking + +var a: string +a = false #ERROR diff --git a/tests/reject/tstatret.nim b/tests/reject/tstatret.nim new file mode 100644 index 000000000..ac93ac532 --- /dev/null +++ b/tests/reject/tstatret.nim @@ -0,0 +1,5 @@ +# no statement after return +proc main() = + return + echo("huch?") #ERROR_MSG statement not allowed after + diff --git a/tests/reject/tstmtexp.nim b/tests/reject/tstmtexp.nim new file mode 100644 index 000000000..f4d83e83f --- /dev/null +++ b/tests/reject/tstmtexp.nim @@ -0,0 +1,3 @@ +# Test 3 + +1+4 #ERROR_MSG value returned by statement has to be discarded diff --git a/tests/reject/ttempl2.nim b/tests/reject/ttempl2.nim new file mode 100644 index 000000000..fba6bd0cb --- /dev/null +++ b/tests/reject/ttempl2.nim @@ -0,0 +1,14 @@ +template declareInScope(x: expr, t: typeDesc): stmt = + var x: t + +template declareInNewScope(x: expr, t: typeDesc): stmt = + # open a new scope: + block: + var x: t + +declareInScope(a, int) +a = 42 # works, `a` is known here + +declareInNewScope(b, int) +b = 42 #ERROR_MSG undeclared identifier: 'b' + diff --git a/tests/reject/tunderscores.nim b/tests/reject/tunderscores.nim new file mode 100644 index 000000000..459cfda30 --- /dev/null +++ b/tests/reject/tunderscores.nim @@ -0,0 +1,7 @@ +# Bug #502670 + +var ef_ = 3 #ERROR_MSG invalid token: _ +var a__b = 1 +var c___d = 2 +echo(ab, cd, ef_) + diff --git a/tests/reject/typredef.nim b/tests/reject/typredef.nim new file mode 100644 index 000000000..a77d91f40 --- /dev/null +++ b/tests/reject/typredef.nim @@ -0,0 +1,3 @@ +type + Uint8 = Uint8 #ERROR_MSG illegal recursion in type 'Uint8' + |