mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-24 07:31:41 +00:00
Merge branch 'devel' into pr_openmp
This commit is contained in:
@@ -727,7 +727,7 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
|
||||
n[0] = ex
|
||||
result.add(n)
|
||||
|
||||
of nkCast, nkHiddenStdConv, nkHiddenSubConv, nkConv, nkObjDownConv,
|
||||
of nkCast, nkHiddenStdConv, nkHiddenSubConv, nkConv, nkObjDownConv, nkObjUpConv,
|
||||
nkDerefExpr, nkHiddenDeref:
|
||||
var ns = false
|
||||
for i in ord(n.kind == nkCast)..<n.len:
|
||||
|
||||
@@ -981,7 +981,7 @@ proc setGenericParams(c: PContext, n, expectedParams: PNode) =
|
||||
if e.typ == nil:
|
||||
n[i].typ = errorType(c)
|
||||
else:
|
||||
n[i].typ = e.typ.skipTypes({tyTypeDesc})
|
||||
n[i].typ = e.typ
|
||||
|
||||
proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym, doError: bool): PNode =
|
||||
assert n.kind == nkBracketExpr
|
||||
|
||||
@@ -160,8 +160,7 @@ proc matchGenericParam(m: var TCandidate, formal: PType, n: PNode) =
|
||||
arg = newTypeS(tyStatic, m.c, son = evaluated.typ)
|
||||
arg.n = evaluated
|
||||
elif formalBase.kind == tyTypeDesc:
|
||||
if arg.kind != tyTypeDesc:
|
||||
arg = makeTypeDesc(m.c, arg)
|
||||
discard # if arg is not tyTypeDesc, typeRel will report the mismatch
|
||||
else:
|
||||
arg = arg.skipTypes({tyTypeDesc})
|
||||
let tm = typeRel(m, formal, arg)
|
||||
@@ -2186,9 +2185,9 @@ proc implicitConv(kind: TNodeKind, f: PType, arg: PNode, m: TCandidate,
|
||||
result.typ = errorType(c)
|
||||
else:
|
||||
result.typ = f.skipTypes({tySink})
|
||||
# keep varness
|
||||
# keep varness, but don't wrap lent types with var
|
||||
if arg.typ != nil and arg.typ.kind == tyVar:
|
||||
result.typ = toVar(result.typ, tyVar, c.idgen)
|
||||
result.typ = toVar(result.typ.skipTypes({tyLent}), tyVar, c.idgen)
|
||||
# copy the tfVarIsPtr flag
|
||||
result.typ.flags = arg.typ.flags
|
||||
else:
|
||||
|
||||
@@ -2127,7 +2127,7 @@ can be used in an `isolate` context:
|
||||
`=destroy`(dest.value)
|
||||
```
|
||||
|
||||
The `.sendable` pragma itself is an experimenal, unchecked, unsafe annotation. It is
|
||||
The `.sendable` pragma itself is an experimental, unchecked, unsafe annotation. It is
|
||||
currently only used by `Isolated[T]`.
|
||||
|
||||
Virtual pragma
|
||||
|
||||
@@ -276,9 +276,9 @@ This parser has 2 modes for inline markup:
|
||||
|
||||
2) Compatibility mode which is RST rules.
|
||||
|
||||
.. Note:: in both modes the parser interpretes text between single
|
||||
.. Note:: in both modes the parser interprets text between single
|
||||
backticks (code) identically:
|
||||
backslash does not escape; the only exception: ``\`` folowed by `
|
||||
backslash does not escape; the only exception: ``\`` followed by `
|
||||
does escape so that we can always input a single backtick ` in
|
||||
inline code. However that makes impossible to input code with
|
||||
``\`` at the end in *single* backticks, one must use *double*
|
||||
|
||||
@@ -52,7 +52,7 @@ Options:
|
||||
nimgrep --filenames # In current dir
|
||||
nimgrep --filenames "" DIRECTORY
|
||||
# Note empty pattern "", lists all files in DIRECTORY
|
||||
* Interprete patterns:
|
||||
* Interpret patterns:
|
||||
--peg PATTERN and PAT are Peg
|
||||
--re PATTERN and PAT are regular expressions (default)
|
||||
--rex, -x use the "extended" syntax for the regular expression
|
||||
|
||||
@@ -27,7 +27,7 @@ Nim runs on a wide variety of platforms. Support on amd64 and i386 is tested reg
|
||||
- ppc64el (aka ppc64le)
|
||||
- riscv64
|
||||
|
||||
The following platforms are seldomly tested:
|
||||
The following platforms are rarely tested:
|
||||
|
||||
- alpha
|
||||
- hppa
|
||||
|
||||
@@ -20,8 +20,8 @@ notation meaning
|
||||
as they succeed. Indicate success if all succeeded.
|
||||
Otherwise, do not consume any text and indicate failure.
|
||||
The sequence's precedence is higher than that of ordered
|
||||
choice: ``A B / C`` means ``(A B) / Z`` and
|
||||
not ``A (B / Z)``.
|
||||
choice: ``A B / C`` means ``(A B) / C`` and
|
||||
not ``A (B / C)``.
|
||||
``(E)`` Grouping: Parenthesis can be used to change
|
||||
operator priority.
|
||||
``{E}`` Capture: Apply expression `E` and store the substring
|
||||
|
||||
@@ -15,6 +15,9 @@ template formatStr*(howExpr, namegetter, idgetter): untyped =
|
||||
val.add(how[i])
|
||||
i += 1
|
||||
else:
|
||||
if i + 1 >= how.len:
|
||||
raise newException(ValueError, "Syntax error in format string at " & $i)
|
||||
|
||||
if how[i + 1] == '$':
|
||||
val.add('$')
|
||||
i += 2
|
||||
@@ -27,7 +30,7 @@ template formatStr*(howExpr, namegetter, idgetter): untyped =
|
||||
i += 1
|
||||
var id {.inject.} = 0
|
||||
while i < how.len and how[i] in {'0'..'9'}:
|
||||
id += (id * 10) + (ord(how[i]) - ord('0'))
|
||||
id = (id * 10) + (ord(how[i]) - ord('0'))
|
||||
i += 1
|
||||
val.add(idgetter)
|
||||
lastNum = id + 1
|
||||
@@ -44,6 +47,8 @@ template formatStr*(howExpr, namegetter, idgetter): untyped =
|
||||
while i < how.len and how[i] != '}':
|
||||
name.add(how[i])
|
||||
i += 1
|
||||
if i >= how.len or how[i] != '}':
|
||||
raise newException(ValueError, "Syntax error in format string at " & $i)
|
||||
i += 1
|
||||
val.add(namegetter)
|
||||
else:
|
||||
|
||||
@@ -1946,9 +1946,14 @@ proc withTimeout*[T](fut: Future[T], timeout: int): owned(Future[bool]) =
|
||||
retFuture.fail(fut.error)
|
||||
else:
|
||||
retFuture.complete(true)
|
||||
# Timeout side lost; drop its callback to avoid retaining closures/futures.
|
||||
timeoutFuture.clearCallbacks()
|
||||
timeoutFuture.callback =
|
||||
proc () =
|
||||
if not retFuture.finished: retFuture.complete(false)
|
||||
if not retFuture.finished:
|
||||
retFuture.complete(false)
|
||||
# Wrapped future side lost; drop its callback to avoid retaining closures/futures.
|
||||
fut.clearCallbacks()
|
||||
return retFuture
|
||||
|
||||
proc accept*(socket: AsyncFD,
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
## stream interface.
|
||||
##
|
||||
## .. warning:: Due to the use of `pointer`, the `readData`, `peekData` and
|
||||
## `writeData` interfaces are not available on the compile-time VM, and must
|
||||
## be cast from a `ptr string` on the JS backend. However, `readDataStr` is
|
||||
## available generally in place of `readData`.
|
||||
## `writeData` interfaces are not available on the compile-time VM, and must
|
||||
## be cast from a `ptr string` on the JS backend. However, `readDataStr` is
|
||||
## available generally in place of `readData`.
|
||||
##
|
||||
## Basic usage
|
||||
## ===========
|
||||
|
||||
@@ -219,16 +219,16 @@ elif someVcc:
|
||||
elif mem == ATOMIC_ACQ_REL: fence()
|
||||
elif mem == ATOMIC_SEQ_CST: fence()
|
||||
|
||||
proc atomicStoreN*[T: AtomType](p: ptr T, val: T, mem: static[AtomMemModel]) =
|
||||
proc atomicStoreN*[T: AtomType](p: ptr T, val: T, mem: static[AtomMemModel]) {.enforcenoraises.} =
|
||||
barrier(mem)
|
||||
p[] = val
|
||||
|
||||
proc atomicLoadN*[T: AtomType](p: ptr T, mem: static[AtomMemModel]): T =
|
||||
proc atomicLoadN*[T: AtomType](p: ptr T, mem: static[AtomMemModel]): T {.enforcenoraises.} =
|
||||
result = p[]
|
||||
barrier(mem)
|
||||
|
||||
proc atomicCompareExchangeN*[T: ptr](p, expected: ptr T, desired: T,
|
||||
weak: bool, success_memmodel: AtomMemModel, failure_memmodel: AtomMemModel): bool =
|
||||
weak: bool, success_memmodel: AtomMemModel, failure_memmodel: AtomMemModel): bool {.enforcenoraises.} =
|
||||
when sizeof(T) == 8:
|
||||
interlockedCompareExchange64(p, cast[int64](desired), cast[int64](expected[])) ==
|
||||
cast[int64](expected[])
|
||||
@@ -236,7 +236,7 @@ elif someVcc:
|
||||
interlockedCompareExchange32(p, cast[int32](desired), cast[int32](expected[])) ==
|
||||
cast[int32](expected[])
|
||||
|
||||
proc atomicExchangeN*[T: ptr](p: ptr T, val: T, mem: AtomMemModel): T =
|
||||
proc atomicExchangeN*[T: ptr](p: ptr T, val: T, mem: AtomMemModel): T {.enforcenoraises.} =
|
||||
when sizeof(T) == 8:
|
||||
cast[T](interlockedExchange64(p, cast[int64](val)))
|
||||
elif sizeof(T) == 4:
|
||||
|
||||
@@ -3,7 +3,7 @@ cmd: "nim check $options --hints:off $file"
|
||||
action: "reject"
|
||||
nimout:'''
|
||||
tpointerprocs.nim(22, 11) Error: 'foo' doesn't have a concrete type, due to unspecified generic parameters.
|
||||
tpointerprocs.nim(34, 14) Error: type mismatch: got <int>
|
||||
tpointerprocs.nim(34, 14) Error: type mismatch: got <typedesc[int]>
|
||||
but expected one of:
|
||||
proc foo(x: int | float; y: int or string): float
|
||||
first type mismatch at position: 2 in generic parameters
|
||||
|
||||
12
tests/iter/tclosureiter_objupconv_methodawait.nim
Normal file
12
tests/iter/tclosureiter_objupconv_methodawait.nim
Normal file
@@ -0,0 +1,12 @@
|
||||
discard """
|
||||
cmd: "nim c $file"
|
||||
"""
|
||||
|
||||
import std/asyncdispatch
|
||||
|
||||
type
|
||||
A {.inheritable.} = ref object
|
||||
B = ref object of A
|
||||
|
||||
method a(x: A): Future[A] {.async, base.} =
|
||||
B(await a(B()))
|
||||
@@ -14,9 +14,15 @@ block: # replace
|
||||
check("123".replace(re"(\d)(\d)", "$#$#") == "123")
|
||||
check("123".replace(re"(?<foo>\d)(\d)", "$foo$#$#") == "1123")
|
||||
check("123".replace(re"(?<foo>\d)(\d)", "${foo}$#$#") == "1123")
|
||||
check("abcdefghijklm".replace(re"(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)", "$12") == "l")
|
||||
|
||||
block: # replacing missing captures should throw instead of segfaulting
|
||||
expect IndexDefect: discard "ab".replace(re"(a)|(b)", "$1$2")
|
||||
expect IndexDefect: discard "b".replace(re"(a)?(b)", "$1$2")
|
||||
expect KeyError: discard "b".replace(re"(a)?", "${foo}")
|
||||
expect KeyError: discard "b".replace(re"(?<foo>a)?", "${foo}")
|
||||
|
||||
block: # malformed replacement syntax should throw instead of OOB crash
|
||||
expect ValueError: discard "a".replace(re"a", "$")
|
||||
expect ValueError: discard "a".replace(re"a", "x$")
|
||||
expect ValueError: discard "a".replace(re"a", "${foo")
|
||||
|
||||
13
tests/typerel/t25262.nim
Normal file
13
tests/typerel/t25262.nim
Normal file
@@ -0,0 +1,13 @@
|
||||
discard """
|
||||
errormsg: "type mismatch"
|
||||
output: '''
|
||||
t25262.nim(13, 5) Error: type mismatch: got <>
|
||||
but expected one of:
|
||||
proc v[T: typedesc]()
|
||||
|
||||
expression: v[0]()
|
||||
'''
|
||||
"""
|
||||
|
||||
proc v[T: typedesc]() = discard
|
||||
v[0]()
|
||||
@@ -23,3 +23,18 @@ proc varProc(x: var int) =
|
||||
doAssert: not compiles(test_lent(x) = 1)
|
||||
doAssert: not compiles(varProc(test_lent(x)))
|
||||
|
||||
type X = tuple[a: int, b: int]
|
||||
|
||||
type ArrayBuf*[N: static int, T] = object
|
||||
buf*: array[N, T]
|
||||
|
||||
var v: ArrayBuf[32, X]
|
||||
|
||||
|
||||
# proc `[]`*[N, T](b: var ArrayBuf[N, T], i: BackwardsIndex): lent T = # works
|
||||
# b.buf[i]
|
||||
|
||||
template `[]`*[N, T](b: var ArrayBuf[N, T], i: BackwardsIndex): lent T =
|
||||
b.buf[i]
|
||||
|
||||
doAssert $v[^4] == "(a: 0, b: 0)"
|
||||
|
||||
Reference in New Issue
Block a user