forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bugs with dot & call operators [backport] (nim-lang#20931)
* better error messages for dot operators [backport] fixes nim-lang#13063 * also fixes nim-lang#7777 * fix nim-lang#6981 and nim-lang#9831 too * fix * minor improvement * sus test fixes * make test multiplatform lol * fix nimsuggest test, extra improvements
- Loading branch information
Showing
6 changed files
with
156 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
discard """ | ||
action: reject | ||
cmd: '''nim check $options $file''' | ||
matrix: "; -d:testWithout" | ||
""" | ||
|
||
when not defined(testWithout): # test for same errors before and after | ||
{.experimental: "dotOperators".} | ||
{.experimental: "callOperator".} | ||
|
||
# issue #13063 | ||
|
||
block: | ||
type Foo = object | ||
type Bar = object | ||
x1: int | ||
var b: Bar | ||
block: | ||
template `.`(a: Foo, b: untyped): untyped = 123 | ||
echo b.x #[tt.Error | ||
^ undeclared field: 'x' for type terrmsgs.Bar [type declared in terrmsgs.nim(15, 8)]]# | ||
block: | ||
template `.()`(a: Foo, b: untyped): untyped = 123 | ||
echo b.x() #[tt.Error | ||
^ attempting to call undeclared routine: 'x']# | ||
block: | ||
template `.=`(a: Foo, b: untyped, c: untyped) = b = c | ||
b.x = 123 #[tt.Error | ||
^ undeclared field: 'x=' for type terrmsgs.Bar [type declared in terrmsgs.nim(15, 8)]]# | ||
# yeah it says x= but does it matter in practice | ||
block: | ||
template `()`(a: Foo, b: untyped, c: untyped) = echo "something" | ||
|
||
# completely undeclared:: | ||
xyz(123) #[tt.Error | ||
^ undeclared identifier: 'xyz']# | ||
|
||
# already declared routine: | ||
min(123) #[tt.Error | ||
^ type mismatch: got <int literal(123)>]# | ||
|
||
# non-routine type shows `()` overloads: | ||
b(123) #[tt.Error | ||
^ attempting to call routine: 'b']# | ||
|
||
echo b.x #[tt.Error | ||
^ undeclared field: 'x' for type terrmsgs.Bar [type declared in terrmsgs.nim(15, 8)]]# | ||
echo b.x() #[tt.Error | ||
^ attempting to call undeclared routine: 'x']# | ||
|
||
# issue #7777 | ||
|
||
import macros | ||
|
||
block: | ||
type TestType = object | ||
private_field: string | ||
|
||
when false: | ||
template getField(obj, field: untyped): untyped = obj.field | ||
|
||
macro `.`(obj: TestType, field: untyped): untyped = | ||
let private = newIdentNode("private_" & $field) | ||
result = quote do: | ||
`obj`.getField(`private`) #[tt.Error | ||
^ attempting to call undeclared routine: 'getField']# | ||
|
||
var tt: TestType | ||
discard tt.field | ||
|
||
block: # related to issue #6981 | ||
proc `()`(a:string, b:string):string = a & b | ||
proc mewSeq[T](a,b:int)=discard | ||
proc mewSeq[T](c:int)= discard | ||
mewSeq[int]() #[tt.Error | ||
^ type mismatch: got <>]# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# issue #6981 | ||
|
||
import std/assertions | ||
|
||
{.experimental: "callOperator".} | ||
|
||
block: # issue #6981 | ||
proc `()`(a:string, b:string):string = a & b | ||
|
||
var s = newSeq[int](3) | ||
|
||
doAssert s == @[0, 0, 0] | ||
|
||
block: # generalized example from #6981 | ||
proc mewSeq[T](a: int)=discard | ||
proc mewSeq[T]()= discard | ||
mewSeq[int]() | ||
|
||
block: # issue #9831 | ||
type Foo = object | ||
proc `()`(foo: Foo) = discard | ||
let x = newSeq[int]() |