typetraits.$: $((int, float), int) is now "((int, float), int)" instead of "(tuple of (int, float), int)" (#14812)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
parent
dc5a40f3f3
commit
a6cbe58e8c
6 changed files with 11 additions and 12 deletions
|
|
@ -115,7 +115,9 @@
|
||||||
- `macros.newLit` now preserves named vs unnamed tuples; use `-d:nimHasWorkaround14720` to keep old behavior
|
- `macros.newLit` now preserves named vs unnamed tuples; use `-d:nimHasWorkaround14720` to keep old behavior
|
||||||
- Add `random.gauss`, that uses the ratio of uniforms method of sampling from a Gaussian distribution.
|
- Add `random.gauss`, that uses the ratio of uniforms method of sampling from a Gaussian distribution.
|
||||||
- Add `typetraits.elementType` to get element type of an iterable.
|
- Add `typetraits.elementType` to get element type of an iterable.
|
||||||
- `typetraits.$`: `$(int,)` is now `"(int,)"`; `$tuple[]` is now `"tuple[]"`
|
- `typetraits.$` changes: `$(int,)` is now `"(int,)"` instead of `"(int)"`;
|
||||||
|
`$tuple[]` is now `"tuple[]"` instead of `"tuple"`;
|
||||||
|
`$((int, float), int)` is now `"((int, float), int)"` instead of `"(tuple of (int, float), int)"`
|
||||||
- add `macros.extractDocCommentsAndRunnables` helper
|
- add `macros.extractDocCommentsAndRunnables` helper
|
||||||
|
|
||||||
- `strformat.fmt` and `strformat.&` support `= specifier`. `fmt"{expr=}"` now expands to `fmt"expr={expr}"`.
|
- `strformat.fmt` and `strformat.&` support `= specifier`. `fmt"{expr=}"` now expands to `fmt"expr={expr}"`.
|
||||||
|
|
|
||||||
|
|
@ -636,8 +636,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||||
elif t.len == 0:
|
elif t.len == 0:
|
||||||
result = "tuple[]"
|
result = "tuple[]"
|
||||||
else:
|
else:
|
||||||
if prefer == preferTypeName: result = "("
|
result = "("
|
||||||
else: result = "tuple of ("
|
|
||||||
for i in 0..<t.len:
|
for i in 0..<t.len:
|
||||||
result.add(typeToString(t[i]))
|
result.add(typeToString(t[i]))
|
||||||
if i < t.len - 1: result.add(", ")
|
if i < t.len - 1: result.add(", ")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "invalid type: 'empty' in this context: 'array[0..0, tuple of (string, seq[empty])]' for var"
|
errormsg: "invalid type: 'empty' in this context: 'array[0..0, (string, seq[empty])]' for var"
|
||||||
line: 8
|
line: 8
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@ proc f(b: B)
|
||||||
but expression 'A()' is of type: A
|
but expression 'A()' is of type: A
|
||||||
|
|
||||||
expression: f(A(), "extra")
|
expression: f(A(), "extra")
|
||||||
tsigmatch.nim(125, 6) Error: type mismatch: got <tuple of (string, proc (){.gcsafe, locks: 0.})>
|
tsigmatch.nim(125, 6) Error: type mismatch: got <(string, proc (){.gcsafe, locks: 0.})>
|
||||||
but expected one of:
|
but expected one of:
|
||||||
proc foo(x: (string, proc ()))
|
proc foo(x: (string, proc ()))
|
||||||
first type mismatch at position: 1
|
first type mismatch at position: 1
|
||||||
required type for x: tuple of (string, proc (){.closure.})
|
required type for x: (string, proc (){.closure.})
|
||||||
but expression '("foobar", proc () = echo(["Hello!"]))' is of type: tuple of (string, proc (){.gcsafe, locks: 0.})
|
but expression '("foobar", proc () = echo(["Hello!"]))' is of type: (string, proc (){.gcsafe, locks: 0.})
|
||||||
|
|
||||||
expression: foo(("foobar", proc () = echo(["Hello!"])))
|
expression: foo(("foobar", proc () = echo(["Hello!"])))
|
||||||
tsigmatch.nim(132, 11) Error: type mismatch: got <proc (s: string): string{.noSideEffect, gcsafe, locks: 0.}>
|
tsigmatch.nim(132, 11) Error: type mismatch: got <proc (s: string): string{.noSideEffect, gcsafe, locks: 0.}>
|
||||||
|
|
|
||||||
|
|
@ -52,10 +52,8 @@ block: # name, `$`
|
||||||
doAssert $tuple[] == "tuple[]"
|
doAssert $tuple[] == "tuple[]"
|
||||||
doAssert $(int,) == "(int,)"
|
doAssert $(int,) == "(int,)"
|
||||||
doAssert $(int, float) == "(int, float)"
|
doAssert $(int, float) == "(int, float)"
|
||||||
doAssert $((int), tuple[], tuple[a: uint], tuple[a: uint, b: float], (int,), (int, float)) == "(int, tuple[], tuple[a: uint], tuple[a: uint, b: float], tuple of (int,), tuple of (int, float))"
|
doAssert $((int), tuple[], tuple[a: uint], tuple[a: uint, b: float], (int,), (int, float)) ==
|
||||||
# xxx this is inconsistent, it should be:
|
"(int, tuple[], tuple[a: uint], tuple[a: uint, b: float], (int,), (int, float))"
|
||||||
# "(int, tuple[], tuple[a: uint], tuple[a: uint, b: float], (int,), (int, float))"
|
|
||||||
# which matches how you write it, is consistent with `$(int,)`, and is un-ambiguous.
|
|
||||||
|
|
||||||
block: # typeToString
|
block: # typeToString
|
||||||
type MyInt = int
|
type MyInt = int
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ discard """
|
||||||
# bug #7937
|
# bug #7937
|
||||||
|
|
||||||
template printError(error: typed) =
|
template printError(error: typed) =
|
||||||
# Error: inconsistent typing for reintroduced symbol 'instInfo': previous type was: tuple[filename: string, line: int, column: int]; new type is: tuple of (string, int, int)
|
# Error: inconsistent typing for reintroduced symbol 'instInfo': previous type was: tuple[filename: string, line: int, column: int]; new type is: (string, int, int)
|
||||||
let instInfo {.gensym.} = instantiationInfo()
|
let instInfo {.gensym.} = instantiationInfo()
|
||||||
echo "Error at ", instInfo.filename, ':', instInfo.line, ": ", error
|
echo "Error at ", instInfo.filename, ':', instInfo.line, ": ", error
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue