You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import json
let foo = (key1: 10, key2: 5)
echo $%foo
# This code should be a minimum reproducible example:# try to simplify and minimize as much as possible. If it's a compiler# issue, try to minimize further by removing any imports if possible.
Current Output
please check whether the problem still exists in git head before posting,
see rebuilding the compiler.
Error: type mismatch: got <tuple[key1: int, key2: int]>
but expected one of:
proc `%`(b: bool): JsonNode
first type mismatch at position: 1
required type for b: bool
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`(keyVals: openArray[tuple[key: string, val: JsonNode]]): JsonNode
first type mismatch at position: 1
required type for keyVals: openArray[tuple[key: string, val: JsonNode]]
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`(n: BiggestInt): JsonNode
first type mismatch at position: 1
required type for n: BiggestInt
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`(n: BiggestUInt): JsonNode
first type mismatch at position: 1
required type for n: BiggestUInt
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`(n: float): JsonNode
first type mismatch at position: 1
required type for n: float
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`(n: int): JsonNode
first type mismatch at position: 1
required type for n: int
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`(n: uint): JsonNode
first type mismatch at position: 1
required type for n: uint
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`(o: enum): JsonNode
first type mismatch at position: 1
required type for o: enum
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`(o: ref object): JsonNode
first type mismatch at position: 1
required type for o: ref object
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`(s: string): JsonNode
first type mismatch at position: 1
required type for s: string
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`[T: object](o: T): JsonNode
first type mismatch at position: 1
required type for o: T: object
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`[T](elements: openArray[T]): JsonNode
first type mismatch at position: 1
required type for elements: openArray[T]
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`[T](opt: Option[T]): JsonNode
first type mismatch at position: 1
required type for opt: Option[%.T]
but expression 'foo' is of type: tuple[key1: int, key2: int]
proc `%`[T](table: Table[string, T] | OrderedTable[string, T]): Js required type for table: Table[system.string, %.T] or OrderedTable[system.string, %.T]
but expression 'foo' is of type: tuple[key1: int, key2:rderedTab int]
template `%`(j: JsonNode): JsonNode int]
first type mismatch at position: 1
required type for j: JsonNode
but expression 'foo' is of type: tuple[key1: int, key2: int] int]
expression: %foo
Expected Output
{"key1": 10, "key2": 5}
Possible Solution
In the file json.nim, line 370:
proc`%`*[T: object](o: T): JsonNode=## Construct JsonNode from tuples and objects.result=newJObject()
for k, v in o.fieldPairs: result[k] =%v
Change the generic type to [T: object or tuple] can perfectly solve this problem.
proc`%`*[T: objectortuple](o: T): JsonNode=## Construct JsonNode from tuples and objects.result=newJObject()
for k, v in o.fieldPairs: result[k] =%v
Additional Information
Current nim version:
$ nim -v
Nim Compiler Version 1.4.2 [Windows: amd64]
Compiled at 2020-11-30
Copyright (c) 2006-2020 by Andreas Rumpf
active boot switches: -d:release
The text was updated successfully, but these errors were encountered:
Function
echo
outputs the wrong string.Example
Current Output
please check whether the problem still exists in git head before posting,
see rebuilding the compiler.
Expected Output
Possible Solution
In the file
json.nim
, line 370:Change the generic type to
[T: object or tuple]
can perfectly solve this problem.Additional Information
Current nim version:
The text was updated successfully, but these errors were encountered: