Merge branch 'type-classes' into upstream

This commit is contained in:
Zahary Karadjov 2013-09-03 03:14:56 +03:00
commit 6082595e96
27 changed files with 594 additions and 249 deletions

View file

@ -1,31 +1,26 @@
discard """
output: '''obj has '==': false
int has '==': true
false
true
true
no'''
"""
# test the new 'compiles' feature:
template supports(opr, x: expr): bool {.immediate.} =
compiles(opr(x)) or compiles(opr(x, x))
template ok(x: expr): stmt =
static: assert(x)
template no(x: expr): stmt =
static: assert(not x)
type
TObj = object
var
myObj {.compileTime.}: TObj
echo "obj has '==': ", supports(`==`, myObj)
echo "int has '==': ", supports(`==`, 45)
ok supports(`==`, myObj)
ok supports(`==`, 45)
echo supports(`++`, 34)
echo supports(`not`, true)
echo supports(`+`, 34)
no supports(`++`, 34)
ok supports(`not`, true)
ok supports(`+`, 34)
no compiles(4+5.0 * "hallo")
when compiles(4+5.0 * "hallo"):
echo "yes"
else:
echo "no"

View file

@ -3,11 +3,10 @@ discard """
line: 11
errormsg: "expression \'a()\' cannot be called"
"""
# Tests the new check in the semantic pass
var
a: int
a() #ERROR_MSG expression 'a()' cannot be called
# Tests the new check in the semantic pass
var
a: int
a() #ERROR_MSG expression 'a()' cannot be called

View file

@ -1,18 +1,18 @@
discard """
file: "topaque.nim"
line: 16
errormsg: "undeclared field: \'buffer\'"
errormsg: "undeclared identifier: \'buffer\'"
"""
# 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'
# 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'

View file

@ -1,12 +1,10 @@
discard """
file: "twrongtupleaccess.nim"
line: 9
errormsg: "undeclared field: \'setBLAH\'"
errormsg: "undeclared identifier: \'setBLAH\'"
"""
# Bugfix
var v = (5.0, 10.0)
v.setBLAH(10)