-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Below works:
import strformat, typetraits
type Person = tuple[name: string, age:int]
let person: Person = ("Peter", 30)
echo fmt"Tuple person of type {$person.type} = {person}"Tuple person of type Person = (name: "Peter", age: 30)
Below fails:
import strformat, typetraits
type Person = tuple[name: string, age:int]
let person: Person = ("Peter", 30)
echo fmt"Tuple person of type {person.type.name} = {person}"Hint: typetraits [Processing]
nim_src_2f8wWD.nim(7, 9) template/generic instantiation from here
lib/pure/strformat.nim(260, 8) Error: type mismatch: got <string, type string>
but expected one of:
proc add(x: var string; y: string)
first type mismatch at position: 2
required type: string
but expression 'type(person).name' is of type: type string
proc add(x: var string; y: char)
first type mismatch at position: 2
required type: char
but expression 'type(person).name' is of type: type string
proc add(result: var string; x: int64)
first type mismatch at position: 2
required type: int64
but expression 'type(person).name' is of type: type string
proc add(result: var string; x: float)
first type mismatch at position: 2
required type: float
but expression 'type(person).name' is of type: type string
proc add(x: var string; y: cstring)
first type mismatch at position: 2
required type: cstring
but expression 'type(person).name' is of type: type string
proc add[T](x: var seq[T]; y: openArray[T])
first type mismatch at position: 1
required type: var seq[T]
but expression 'fmtRes218041' is of type: string
proc add[T](x: var seq[T]; y: T)
first type mismatch at position: 1
required type: var seq[T]
but expression 'fmtRes218041' is of type: string
expression: add(fmtRes218041, type(person).name)
type.name works again if I change the tuple field name to anything
but name:
import strformat, typetraits
type Person = tuple[namex: string, age:int]
let person: Person = ("Peter", 30)
echo fmt"Tuple person of type {person.type.name} = {person}"Tuple person of type Person = (namex: "Peter", age: 30)
Metadata
Metadata
Assignees
Labels
No labels