Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Mar 22, 2020
1 parent 162b514 commit 0f408aa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
2 changes: 0 additions & 2 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# this module does the semantic checking for expressions
# included from sem.nim

import std/wrapnils

const
errExprXHasNoType = "expression '$1' has no type (or is ambiguous)"
errXExpectsTypeOrValue = "'$1' expects a type or value"
Expand Down
58 changes: 44 additions & 14 deletions tests/magics/tresolve_overloads.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Nim/tests/magics/tresolve_overloads.nim:133:28: $ = closedSymChoice:
]#

import ./mresolves
import ./mresolve_overloads

template bail() = static: doAssert false

Expand Down Expand Up @@ -43,7 +44,7 @@ macro fun8(c: static bool): untyped = discard
proc fun8(d: var int) = d.inc

proc main()=
static:
block: # overloadExists with nkCall
doAssert overloadExists(fun4(1))
doAssert not compiles(fun4(1))
doAssert overloadExists(fun4(1))
Expand Down Expand Up @@ -77,19 +78,48 @@ proc main()=
doAssert overloadExists(fun7(1))
doAssert not overloadExists(fun7())

block: # dot accesors
type Foo = object
bar1: int
template bar2(a: Foo) = discard
template bar3[T](a: T) = discard
doAssert compiles(Foo().bar1)
doAssert overloadExists(Foo().bar1)
const foo = Foo()
doAssert overloadExists(foo.bar1)
doAssert overloadExists(foo.bar2)
doAssert overloadExists(foo.bar3)
doAssert not overloadExists(foo.bar4)
block: # overloadExists with nkCall dot accesors
type Foo = object
bar1: int
var foo: Foo

template bar2(a: Foo) = discard
template bar3[T](a: T): int = 0

proc bar4(a: int) = discard

template bar5(a: int) = discard
template bar5(a: Foo) = discard

doAssert not declared(mresolve_overloads.nonexistant)
doAssert declared(mresolve_overloads.foo3)
doAssert not declared(foo.bar1)
doAssert not overloadExists(mresolve_overloads.nonexistant)
doAssert overloadExists(mresolve_overloads.foo3)

doAssert not overloadExists(nonexistant(foo))
doAssert not overloadExists(foo.nonexistant)
doAssert compiles(Foo().bar1)
doAssert compiles(Foo().bar1)
doAssert overloadExists(foo.bar2)
doAssert overloadExists(foo.bar3)

doAssert not overloadExists(bar4(foo))
doAssert not overloadExists(foo.bar4)

proc bar4(a: Foo) = discard

doAssert overloadExists(foo.bar4)
doAssert overloadExists(foo.bar5)

doAssert overloadExists(foo.bar1)
doAssert overloadExists(Foo().bar1)

doAssert not compiles(nonexistant.bar1)
doAssert not compiles(overloadExists(nonexistant.bar1))
doAssert not compiles(overloadExists(nonexistant().bar1))

block: # resolveSymbol
doAssert resolveSymbol(fun8(1))(3) == fun8(3)
inspect resolveSymbol(fun8)

Expand Down Expand Up @@ -134,7 +164,6 @@ proc main()=
import std/strutils
import std/macros
import std/macros as macrosAlias
import ./mresolve_overloads

proc main2()=
block:
Expand Down Expand Up @@ -183,4 +212,5 @@ proc main2()=
proc funDecl2(a: int) = discard

main()
static: main()
main2()

0 comments on commit 0f408aa

Please sign in to comment.