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.
fixes nim-lang#11184, fixes nim-lang#22605, fixes nim-lang#20000
- Loading branch information
Showing
9 changed files
with
220 additions
and
22 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
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,23 @@ | ||
# foo0 has 0 overloads | ||
|
||
template myTemplate0*(): string = | ||
foo0(bar) | ||
|
||
# foo1 has 1 overload | ||
|
||
proc foo1(arg: int): string = | ||
"foo1 bad" | ||
|
||
template myTemplate1*(): string = | ||
foo1(bar) | ||
|
||
# foo2 has 2 overloads | ||
|
||
proc foo2(arg: int): string = | ||
"foo2 bad 1" | ||
|
||
proc foo2(arg: string): string = | ||
"foo2 bad 2" | ||
|
||
template myTemplate2*(): string = | ||
foo2(bar) |
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,124 @@ | ||
block: # issue #22605, normal call syntax | ||
const error = "bad" | ||
|
||
template valueOr(self: int, def: untyped): untyped = | ||
case false | ||
of true: "" | ||
of false: | ||
template error: untyped {.used, inject.} = "good" | ||
def | ||
|
||
proc g(T: type): string = | ||
let x = valueOr 123: | ||
return $error | ||
|
||
"ok" | ||
|
||
doAssert g(int) == "good" | ||
|
||
block: # issu #22605, method call syntax | ||
const error = "bad" | ||
|
||
template valueOr(self: int, def: untyped): untyped = | ||
case false | ||
of true: "" | ||
of false: | ||
template error: untyped {.used, inject.} = "good" | ||
def | ||
|
||
proc g(T: type): string = | ||
let x = 123.valueOr: | ||
return $error | ||
|
||
"ok" | ||
|
||
doAssert g(int) == "good" | ||
|
||
block: # issue #22605, template case | ||
template valueOr(self, def: untyped): untyped = | ||
block: | ||
template error: untyped {.used, inject.} = "good" | ||
def | ||
|
||
const error = "bad" | ||
template g: untyped = | ||
let x = 123.valueOr: | ||
$error | ||
x | ||
doAssert g == "good" | ||
|
||
block: # issue #22605, original complex example | ||
type Xxx = enum | ||
error | ||
value | ||
|
||
type | ||
Result[T, E] = object | ||
when T is void: | ||
when E is void: | ||
oResultPrivate*: bool | ||
else: | ||
case oResultPrivate*: bool | ||
of false: | ||
eResultPrivate*: E | ||
of true: | ||
discard | ||
else: | ||
when E is void: | ||
case oResultPrivate*: bool | ||
of false: | ||
discard | ||
of true: | ||
vResultPrivate*: T | ||
else: | ||
case oResultPrivate*: bool | ||
of false: | ||
eResultPrivate*: E | ||
of true: | ||
vResultPrivate*: T | ||
|
||
template valueOr[T: not void, E](self: Result[T, E], def: untyped): untyped = | ||
let s = (self) # TODO avoid copy | ||
case s.oResultPrivate | ||
of true: | ||
s.vResultPrivate | ||
of false: | ||
when E isnot void: | ||
template error: untyped {.used, inject.} = s.eResultPrivate | ||
def | ||
|
||
proc f(): Result[int, cstring] = | ||
Result[int, cstring](oResultPrivate: false, eResultPrivate: "f") | ||
|
||
proc g(T: type): string = | ||
let x = f().valueOr: | ||
return $error | ||
|
||
"ok" | ||
|
||
doAssert g(int) == "f" | ||
|
||
# issue #11184 | ||
|
||
import mopensym | ||
|
||
type | ||
MyType = object | ||
|
||
proc foo0(arg: MyType): string = | ||
"foo0" | ||
|
||
proc foo1(arg: MyType): string = | ||
"foo1" | ||
|
||
proc foo2(arg: MyType): string = | ||
"foo2" | ||
|
||
proc test() = | ||
var bar: MyType | ||
|
||
doAssert myTemplate0() == "foo0" | ||
doAssert myTemplate1() == "foo1" | ||
doAssert myTemplate2() == "foo2" | ||
|
||
test() |
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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
block: # #20002 | ||
block: # issue #20002 | ||
proc bar(x: int): int = 10 | ||
template foo = | ||
proc bar(x: int): int {.gensym.} = x + 2 | ||
doAssert bar(3) == 5 | ||
discard 3.bar # evaluates to 10 but only check if it compiles for now | ||
block: | ||
foo() | ||
|
||
block: # issue #20000, no gensym | ||
proc bar(x: int): int = 10 | ||
template foo = | ||
proc bar(x: int): int = x + 2 | ||
doAssert bar(3) == 5 | ||
doAssert 3.bar == 5 | ||
block: | ||
foo() |