mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
* fixes #21974; fixes sameConstant fieldDefect * add a test case
This commit is contained in:
@@ -1016,7 +1016,7 @@ proc p(n: PNode; c: var Con; s: var Scope; mode: ProcessMode; tmpFlags = {sfSing
|
||||
|
||||
proc sameLocation*(a, b: PNode): bool =
|
||||
proc sameConstant(a, b: PNode): bool =
|
||||
a.kind in nkLiterals and a.intVal == b.intVal
|
||||
a.kind in nkLiterals and b.kind in nkLiterals and a.intVal == b.intVal
|
||||
|
||||
const nkEndPoint = {nkSym, nkDotExpr, nkCheckedFieldExpr, nkBracketExpr}
|
||||
if a.kind in nkEndPoint and b.kind in nkEndPoint:
|
||||
|
||||
@@ -59,3 +59,33 @@ proc bug(): seq[Obj] =
|
||||
# bug #19990
|
||||
let s = bug()
|
||||
doAssert s[0] == (value: 1, arr: @[1])
|
||||
|
||||
block: # bug #21974
|
||||
type Test[T] = ref object
|
||||
values : seq[T]
|
||||
counter: int
|
||||
|
||||
proc newTest[T](): Test[T] =
|
||||
result = new(Test[T])
|
||||
result.values = newSeq[T](16)
|
||||
result.counter = 0
|
||||
|
||||
proc push[T](self: Test[T], value: T) =
|
||||
self.counter += 1
|
||||
if self.counter >= self.values.len:
|
||||
self.values.setLen(self.values.len * 2)
|
||||
self.values[self.counter - 1] = value
|
||||
|
||||
proc pop[T](self: Test[T]): T =
|
||||
result = self.values[0]
|
||||
self.values[0] = self.values[self.counter - 1] # <--- This line
|
||||
self.counter -= 1
|
||||
|
||||
|
||||
type X = tuple
|
||||
priority: int
|
||||
value : string
|
||||
|
||||
var a = newTest[X]()
|
||||
a.push((1, "One"))
|
||||
doAssert a.pop.value == "One"
|
||||
|
||||
Reference in New Issue
Block a user