mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-31 19:03:42 +00:00
Compare commits
4 Commits
pr_disable
...
pr_djd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c1e9e9a18 | ||
|
|
286b7eb6f6 | ||
|
|
73986c03a1 | ||
|
|
88a18de44f |
@@ -1647,9 +1647,13 @@ proc canRaise*(fn: PNode): bool =
|
||||
if fn.typ.n[0].kind == nkSym:
|
||||
result = false
|
||||
else:
|
||||
# A proc-typed value with no explicit raises slot still has
|
||||
# unspecified effects, which sempass2 treats conservatively.
|
||||
# Codegen needs to do the same in order to keep goto-exception
|
||||
# checks after indirect/closure calls.
|
||||
result = ((fn.typ.n[0].len < effectListLen) or
|
||||
(fn.typ.n[0][exceptionEffects] != nil and
|
||||
fn.typ.n[0][exceptionEffects].safeLen > 0))
|
||||
fn.typ.n[0][exceptionEffects] == nil or
|
||||
fn.typ.n[0][exceptionEffects].safeLen > 0)
|
||||
else:
|
||||
result = false
|
||||
|
||||
|
||||
@@ -1308,6 +1308,8 @@ proc allowCStringConv(n: PNode): bool =
|
||||
|
||||
proc track(tracked: PEffects, n: PNode) =
|
||||
case n.kind
|
||||
of nkTypeOfExpr:
|
||||
discard "typeof() never evaluates its operand; not a definite-assignment use"
|
||||
of nkSym:
|
||||
useVar(tracked, n)
|
||||
if n.sym.typ != nil and tfHasAsgn in n.sym.typ.flags:
|
||||
@@ -1557,9 +1559,10 @@ proc track(tracked: PEffects, n: PNode) =
|
||||
message(tracked.config, n.info, warnPtrToCstringConv,
|
||||
$n[1].typ)
|
||||
|
||||
# Check for implicit range conversions
|
||||
# Check for implicit range conversions. Compile-time constants are already
|
||||
# fully known here, so only non-constant values need the downsizing warning.
|
||||
if n.kind == nkHiddenStdConv and (not tracked.isArrayIndexing) and
|
||||
n[1].kind notin {nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit} and
|
||||
getConstExpr(tracked.ownerModule, n[1], tracked.c.idgen, tracked.graph) == nil and
|
||||
shouldWarnRangeConversion(tracked.config, n.info, n.typ, n[1].typ):
|
||||
message(tracked.config, n.info, warnImplicitRangeConversion,
|
||||
typeToString(n[1].typ) & " -> " & typeToString(n.typ))
|
||||
|
||||
@@ -156,8 +156,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||
result = typeAllowedAux(marker, t.elementType, kind, c, flags+{taIsOpenArray})
|
||||
of tySink:
|
||||
# you cannot nest openArrays/sinks/etc.
|
||||
# `sink openarray` is not allowed
|
||||
if kind != skParam or taIsOpenArray in flags or t.elementType.kind in {tySink, tyLent, tyVar, tyOpenArray, tyVarargs}:
|
||||
if kind != skParam or taIsOpenArray in flags or t.elementType.kind in {tySink, tyLent, tyVar}:
|
||||
result = t
|
||||
else:
|
||||
result = typeAllowedAux(marker, t.elementType, kind, c, flags)
|
||||
|
||||
@@ -1842,6 +1842,8 @@ proc genArrAccessOpcode(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode;
|
||||
if dest < 0: dest = c.getTemp(n.typ)
|
||||
if opc in {opcLdArrAddr, opcLdStrIdxAddr} and gfNodeAddr in flags:
|
||||
c.gABC(n, opc, dest, a, b)
|
||||
if c.prc.regInfo[a].kind >= slotTempUnknown:
|
||||
c.prc.regInfo[a].kind = slotTempPerm
|
||||
elif needsRegLoad():
|
||||
var cc = c.getTemp(n.typ)
|
||||
c.gABC(n, opc, cc, a, b)
|
||||
@@ -1858,6 +1860,8 @@ proc genObjAccessAux(c: PCtx; n: PNode; a, b: int, dest: var TDest; flags: TGenF
|
||||
if dest < 0: dest = c.getTemp(n.typ)
|
||||
if {gfNodeAddr} * flags != {}:
|
||||
c.gABC(n, opcLdObjAddr, dest, a, b)
|
||||
if a < c.prc.regInfo.len and c.prc.regInfo[a].kind >= slotTempUnknown:
|
||||
c.prc.regInfo[a].kind = slotTempPerm
|
||||
elif needsRegLoad():
|
||||
var cc = c.getTemp(n.typ)
|
||||
c.gABC(n, opcLdObj, cc, a, b)
|
||||
|
||||
@@ -526,7 +526,7 @@ func commonPrefixLen*[T](c: CritBitTree[T]): int {.inline, since((1, 3)).} =
|
||||
else: c.root.byte
|
||||
else: 0
|
||||
|
||||
proc toCritBitTree*[T](pairs: openArray[(string, T)]): CritBitTree[T] {.since: (1, 3).} =
|
||||
proc toCritBitTree*[T](pairs: sink openArray[(string, T)]): CritBitTree[T] {.since: (1, 3).} =
|
||||
## Creates a new `CritBitTree` that contains the given `pairs`.
|
||||
runnableExamples:
|
||||
doAssert {"a": "0", "b": "1", "c": "2"}.toCritBitTree is CritBitTree[string]
|
||||
@@ -534,7 +534,7 @@ proc toCritBitTree*[T](pairs: openArray[(string, T)]): CritBitTree[T] {.since: (
|
||||
|
||||
for item in pairs: result.incl item[0], item[1]
|
||||
|
||||
proc toCritBitTree*(items: openArray[string]): CritBitTree[void] {.since: (1, 3).} =
|
||||
proc toCritBitTree*(items: sink openArray[string]): CritBitTree[void] {.since: (1, 3).} =
|
||||
## Creates a new `CritBitTree` that contains the given `items`.
|
||||
runnableExamples:
|
||||
doAssert ["a", "b", "c"].toCritBitTree is CritBitTree[void]
|
||||
|
||||
36
tests/ccg/tclosure_err_panic_goto.nim
Normal file
36
tests/ccg/tclosure_err_panic_goto.nim
Normal file
@@ -0,0 +1,36 @@
|
||||
discard """
|
||||
matrix: "; --panics:on"
|
||||
"""
|
||||
# issue #25851: --panics:on must not drop the nimErr_ check after a closure
|
||||
# call whose result is consumed directly (e.g. `result.add elem(src)`).
|
||||
# Regression from #25295.
|
||||
|
||||
type
|
||||
Overrun = object of CatchableError
|
||||
Source = object
|
||||
data: seq[bool]
|
||||
cursor: int
|
||||
ElemFn = proc(src: var Source): bool {.closure.}
|
||||
|
||||
proc drawBool(src: var Source): bool =
|
||||
if src.cursor >= src.data.len: raise newException(Overrun, "exhausted")
|
||||
result = src.data[src.cursor]; inc src.cursor
|
||||
|
||||
proc listRun(elem: ElemFn, src: var Source): seq[bool] =
|
||||
result = @[]
|
||||
while true:
|
||||
if not src.drawBool(): break
|
||||
result.add elem(src) # closure call – the result flows straight
|
||||
# into `add`, which previously caused the
|
||||
# compiler to skip the nimErr_ check.
|
||||
|
||||
let elem: ElemFn = proc(src: var Source): bool = src.drawBool()
|
||||
|
||||
# Both --panics:on and --panics:off must propagate the Overrun.
|
||||
var caught = false
|
||||
try:
|
||||
var src = Source(data: @[true])
|
||||
discard listRun(elem, src)
|
||||
except Overrun:
|
||||
caught = true
|
||||
doAssert caught, "Overrun exception was swallowed"
|
||||
@@ -186,7 +186,7 @@ type
|
||||
TableNonCopyable = object
|
||||
x: seq[(string, MySeqNonCopyable)]
|
||||
|
||||
proc toTable(pairs: openArray[(string, MySeqNonCopyable)]): TableNonCopyable =
|
||||
proc toTable(pairs: sink openArray[(string, MySeqNonCopyable)]): TableNonCopyable =
|
||||
discard
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
discard """
|
||||
cmd: '''nim cpp -d:nimAllocStats --newruntime --threads:on $file'''
|
||||
disabled: true
|
||||
output: '''(field: "value")
|
||||
Indeed
|
||||
axc
|
||||
|
||||
19
tests/init/t25857.nim
Normal file
19
tests/init/t25857.nim
Normal file
@@ -0,0 +1,19 @@
|
||||
discard """
|
||||
output: "1"
|
||||
"""
|
||||
|
||||
# Regression for #25857: `typeof(result)` inside `result`'s initializer must not be
|
||||
# treated as a use-before-initialization of `result`. `typeof` is a type query and
|
||||
# never evaluates its operand, so this compiles and runs.
|
||||
# (Before the fix this errored: "'result' requires explicit initialization" on
|
||||
# {.requiresInit.} return types, breaking the `ok(typeof(result), v)` idiom.)
|
||||
|
||||
type Box[T] {.requiresInit.} = object
|
||||
v: T
|
||||
|
||||
func make[T](_: typedesc[Box[T]], v: T): Box[T] = Box[T](v: v)
|
||||
|
||||
proc f(): Box[int] =
|
||||
make(typeof(result), 1)
|
||||
|
||||
echo f().v
|
||||
30
tests/range/timplicitrangeconsts.nim
Normal file
30
tests/range/timplicitrangeconsts.nim
Normal file
@@ -0,0 +1,30 @@
|
||||
discard """
|
||||
cmd: "nim check $options --hints:off --warning:ImplicitRangeConversion --warningaserror:ImplicitRangeConversion $file"
|
||||
action: "compile"
|
||||
"""
|
||||
|
||||
type
|
||||
E = enum
|
||||
ea, eb
|
||||
|
||||
R = range[eb..eb]
|
||||
I = range[0..3]
|
||||
|
||||
proc accept(r: R) = discard
|
||||
proc accept(i: I) = discard
|
||||
|
||||
var r: R
|
||||
var i: I
|
||||
const enumOk = eb
|
||||
const enumAlias = enumOk
|
||||
const intOk = 1 + 2
|
||||
|
||||
r = eb
|
||||
r = enumOk
|
||||
r = enumAlias
|
||||
accept(eb)
|
||||
accept(enumOk)
|
||||
accept(enumAlias)
|
||||
|
||||
i = intOk
|
||||
accept(intOk)
|
||||
16
tests/vm/t25849.nim
Normal file
16
tests/vm/t25849.nim
Normal file
@@ -0,0 +1,16 @@
|
||||
discard """
|
||||
targets: "c cpp js"
|
||||
"""
|
||||
|
||||
import std/os
|
||||
from std/sequtils import toSeq
|
||||
|
||||
iterator items(a: array[3, string]): lent string {.inline.} =
|
||||
for i in 0..2:
|
||||
yield a[i]
|
||||
|
||||
static:
|
||||
const key = "NIM_TESTS_TOSENV_KEY"
|
||||
for val in items(["a", "b", "c"]):
|
||||
putEnv(key, val)
|
||||
doAssert (key, val) in toSeq(envPairs())
|
||||
Reference in New Issue
Block a user