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.
closes nim-lang#4774, closes nim-lang#7385, closes nim-lang#10019, closes nim-lang#12405, closes nim-lang#12732, closes nim-lang#13270, closes nim-lang#13799, closes nim-lang#15247, closes nim-lang#16128, closes nim-lang#16175, closes nim-lang#16774, closes nim-lang#17527, closes nim-lang#20880, closes nim-lang#21346
- Loading branch information
Showing
16 changed files
with
281 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# issue #16128 | ||
|
||
import std/[tables, hashes] | ||
|
||
type | ||
NodeId*[L] = object | ||
isSource: bool | ||
index: Table[NodeId[L], seq[NodeId[L]]] | ||
|
||
func hash*[L](id: NodeId[L]): Hash = discard | ||
func `==`[L](a, b: NodeId[L]): bool = discard | ||
|
||
proc makeIndex*[T, L](tree: T) = | ||
var parent = NodeId[L]() | ||
var tmp: Table[NodeId[L], seq[NodeId[L]]] | ||
tmp[parent] = @[parent] | ||
|
||
proc simpleTreeDiff*[T, L](source, target: T) = | ||
# Swapping these two lines makes error disappear | ||
var m: Table[NodeId[L], NodeId[L]] | ||
makeIndex[T, L](target) | ||
|
||
var tmp: Table[string, seq[string]] # removing this forward declaration also removes error | ||
|
||
proc diff(x1, x2: string): auto = | ||
simpleTreeDiff[int, string](12, 12) |
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 @@ | ||
block: # issue #17527 | ||
iterator items2[IX, T](a: array[IX, T]): lent T {.inline.} = | ||
var i = low(IX) | ||
if i <= high(IX): | ||
while true: | ||
yield a[i] | ||
if i >= high(IX): break | ||
inc(i) | ||
|
||
proc main() = | ||
var s: seq[string] = @[] | ||
for i in 0..<3: | ||
for (key, val) in items2([("any", "bar")]): | ||
s.add $(i, key, val) | ||
doAssert s == @[ | ||
"(0, \"any\", \"bar\")", | ||
"(1, \"any\", \"bar\")", | ||
"(2, \"any\", \"bar\")" | ||
] | ||
|
||
static: main() |
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,2 @@ | ||
proc count*(s: string): int = | ||
s.len |
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 @@ | ||
var count*: int = 10 |
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 @@ | ||
const count* = 3.142 |
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,10 @@ | ||
# issue #12732 | ||
|
||
import std/macros | ||
const getPrivate3_tmp* = 0 | ||
const foobar1* = 0 # comment this or make private and it'll compile fine | ||
macro foobar4*(): untyped = | ||
newLit "abc" | ||
template currentPkgDir2*: string = foobar4() | ||
macro currentPkgDir2*(dir: string): untyped = | ||
newLit "abc2" |
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,8 @@ | ||
# issue #15247 | ||
|
||
import mdisambsym1, mdisambsym2, mdisambsym3 | ||
|
||
proc twice(n: int): int = | ||
n*2 | ||
|
||
doAssert twice(count) == 20 |
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,5 @@ | ||
# issue #12732 | ||
|
||
import mmacroamb | ||
const s0 = currentPkgDir2 #[tt.Error | ||
^ ambiguous identifier: 'currentPkgDir2' -- use one of the following:]# |
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,13 @@ | ||
block: # issue #13799 | ||
type | ||
X[A, B] = object | ||
a: A | ||
b: B | ||
|
||
Y[A] = X[A, int] | ||
template s(T: type X): X = T() | ||
template t[A, B](T: type X[A, B]): X[A, B] = T() | ||
proc works1(): Y[int] = s(X[int, int]) | ||
proc works2(): Y[int] = t(X[int, int]) | ||
proc works3(): Y[int] = t(Y[int]) | ||
proc broken(): Y[int] = s(Y[int]) |
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,19 @@ | ||
import macros | ||
|
||
block: # issue #7385 | ||
type CustomSeq[T] = object | ||
data: seq[T] | ||
macro `[]`[T](s: CustomSeq[T], args: varargs[untyped]): untyped = | ||
## The end goal is to replace the joker "_" by something else | ||
result = newIntLitNode(10) | ||
proc foo1(): CustomSeq[int] = | ||
result.data.newSeq(10) | ||
# works since no overload matches first argument with type `CustomSeq` | ||
# except magic `[]`, which always matches without checking arguments | ||
doAssert result[_] == 10 | ||
doAssert foo1() == CustomSeq[int](data: newSeq[int](10)) | ||
proc foo2[T](): CustomSeq[T] = | ||
result.data.newSeq(10) | ||
# works fine with generic return type | ||
doAssert result[_] == 10 | ||
doAssert foo2[int]() == CustomSeq[int](data: newSeq[int](10)) |
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,55 @@ | ||
# issue #12405 | ||
|
||
import std/[marshal, streams, times, tables, os, assertions] | ||
|
||
type AiredEpisodeState * = ref object | ||
airedAt * : DateTime | ||
tvShowId * : string | ||
seasonNumber * : int | ||
number * : int | ||
title * : string | ||
|
||
type ShowsWatchlistState * = ref object | ||
aired * : seq[AiredEpisodeState] | ||
|
||
type UiState * = ref object | ||
shows: ShowsWatchlistState | ||
|
||
# Helpers to marshal and unmarshal | ||
proc load * ( state : var UiState, file : string ) = | ||
var strm = newFileStream( file, fmRead ) | ||
|
||
strm.load( state ) | ||
|
||
strm.close() | ||
|
||
proc store * ( state : UiState, file : string ) = | ||
var strm = newFileStream( file, fmWrite ) | ||
|
||
strm.store( state ) | ||
|
||
strm.close() | ||
|
||
# 1. We fill the state initially | ||
var state : UiState = UiState( shows: ShowsWatchlistState( aired: @[] ) ) | ||
|
||
# VERY IMPORTANT: For some reason, small numbers (like 2 or 3) don't trigger the bug. Anything above 7 or 8 on my machine triggers though | ||
for i in 0..30: | ||
var episode = AiredEpisodeState( airedAt: now(), tvShowId: "1", seasonNumber: 1, number: 1, title: "string" ) | ||
|
||
state.shows.aired.add( episode ) | ||
|
||
# 2. Store it in a file with the marshal module, and then load it back up | ||
store( state, "tmarshalsegfault_data" ) | ||
load( state, "tmarshalsegfault_data" ) | ||
removeFile("tmarshalsegfault_data") | ||
|
||
# 3. VERY IMPORTANT: Without this line, for some reason, everything works fine | ||
state.shows.aired[ 0 ] = AiredEpisodeState( airedAt: now(), tvShowId: "1", seasonNumber: 1, number: 1, title: "string" ) | ||
|
||
# 4. And formatting the airedAt date will now trigger the exception | ||
var s = "" | ||
for ep in state.shows.aired: | ||
let x = $ep.seasonNumber & "x" & $ep.number & " (" & $ep.airedAt & ")" | ||
if s.len == 0: s = x | ||
else: doAssert s == x |