-
-
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.
- Loading branch information
Showing
7 changed files
with
201 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
discard """ | ||
nimout: ''' | ||
ProcDef | ||
Sym "foo" | ||
Empty | ||
Empty | ||
FormalParams | ||
Empty | ||
IdentDefs | ||
Sym "x" | ||
Empty | ||
Call | ||
Sym "none" | ||
Sym "Natural" | ||
Empty | ||
Empty | ||
DiscardStmt | ||
Empty | ||
ProcDef | ||
Sym "example" | ||
Empty | ||
Empty | ||
FormalParams | ||
Empty | ||
IdentDefs | ||
Sym "a" | ||
Empty | ||
Sym "thing" | ||
Empty | ||
Empty | ||
DiscardStmt | ||
TupleConstr | ||
Sym "a" | ||
Sym "thing" | ||
''' | ||
""" | ||
|
||
import options, macros | ||
|
||
macro typedTree(n: typed): untyped = | ||
result = n | ||
echo treeRepr n | ||
|
||
# issue #19118 | ||
proc foo(x = none(Natural)) {.typedTree.} = discard | ||
|
||
# issue #12942 | ||
var thing = 2 | ||
proc example(a = thing) {.typedTree.} = | ||
discard (a, thing) |
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,50 @@ | ||
discard """ | ||
output: ''' | ||
seq[string] | ||
@[] | ||
seq[string] | ||
@[] | ||
seq[string] | ||
@[] | ||
seq[string] | ||
@[] | ||
seq[string] | ||
@[] | ||
seq[string] | ||
@[] | ||
''' | ||
""" | ||
|
||
# regression from #24184, see #24191 | ||
|
||
const a: seq[string] = @[] | ||
|
||
proc foo(x = a) = | ||
echo typeof(x) | ||
echo x | ||
|
||
proc bar(x: static seq[string] = a) = | ||
echo typeof(x) | ||
echo x | ||
|
||
# issue #22793 | ||
proc baz(x: static seq[string] = @[]) = | ||
echo typeof(x) | ||
echo x | ||
|
||
import macros | ||
|
||
macro resem(x: typed) = | ||
expectKind x, nnkSym | ||
result = getImpl(x) | ||
|
||
foo() | ||
bar() | ||
baz() | ||
block: | ||
resem(foo) # Error: cannot infer the type of parameter 'x' | ||
resem(bar) | ||
resem(baz) | ||
foo() | ||
bar() | ||
baz() |
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 @@ | ||
block: # issue #22793 | ||
const x = @["a", "b"] | ||
|
||
proc myProc(x: seq[string]): seq[string] = | ||
result = x | ||
doAssert x.myProc() == @["a", "b"] | ||
doAssert x.myProc() == x | ||
|
||
proc myProc2(x: seq[string] = @[]): seq[string] = # Compiler correctly infers that `@[]` is `seq[string]` | ||
result = x | ||
doAssert x.myProc2() == @["a", "b"] | ||
doAssert x.myProc2() == x | ||
|
||
proc myProc3(x: static seq[string]): seq[string] = | ||
result = x | ||
doAssert x.myProc3() == @["a", "b"] | ||
doAssert x.myProc3() == x | ||
|
||
proc myProc4(x: static seq[string] = @[]): seq[string] = # This proc causes a compiler error. Compiler does not infer that `@[]` is `static seq[string]` | ||
result = x | ||
doAssert x.myProc4() == @["a", "b"] | ||
doAssert x.myProc4() == x |
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,29 @@ | ||
# issue #23010 | ||
|
||
type | ||
Result[T, E] = object | ||
case oResult: bool | ||
of false: | ||
discard | ||
of true: | ||
vResult: T | ||
|
||
Opt[T] = Result[T, void] | ||
|
||
template ok[T, E](R: type Result[T, E], x: untyped): R = | ||
R(oResult: true, vResult: x) | ||
|
||
template c[T](v: T): Opt[T] = Opt[T].ok(v) | ||
|
||
type | ||
FixedBytes[N: static[int]] = distinct array[N, byte] | ||
|
||
H = object | ||
d: FixedBytes[2] | ||
|
||
const b = default(H) | ||
template g(): untyped = | ||
const t = default(H) | ||
b | ||
|
||
discard c(g()) |