-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add extractGeneric: extractGeneric(Foo2[float, string], 0) is float
- Loading branch information
1 parent
bbc404d
commit 1c669ab
Showing
3 changed files
with
54 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
discard """ | ||
file: "tsugar.nim" | ||
output: "" | ||
""" | ||
import sugar | ||
import macros | ||
|
||
block extractGeneric: | ||
type Foo[T1, T2]=object | ||
type Foo2=Foo[float, string] | ||
doAssert extractGeneric(Foo[float, string], 1) is string | ||
doAssert extractGeneric(Foo2, 1) is string | ||
# workaround for seq[int].T not working, | ||
# see https://github.com/nim-lang/Nim/issues/8433 | ||
doAssert extractGeneric(seq[int], 0) is int | ||
doAssert extractGeneric(seq[seq[string]], 0) is seq[string] | ||
doAssert: not compiles(extractGeneric(seq[int], 1)) | ||
doAssert extractGeneric(seq[int], -1) is seq | ||
|
||
type Foo3[T] = T | ||
doAssert extractGeneric(Foo3[int], 0) is int |