Hello everyone, I was wondering if I just found a bug or if there is something 
wrong with the following code:
    
    
    #ex1
    
    proc test1(T : typedesc[SomeNumber] = typedesc[float]) : T =
        echo "type is " & $T
        return T(0)
    
    #works
    echo test1(int)
    
    #ex2
    type
        SomeObject[T] = object
            val : T
    
    proc test2(T : typedesc = typedesc[float]) : SomeObject[T] =
        echo "type is " & $T
        return SomeObject[T](val : default(T))
    
    #works
    echo test2(int)
    
    #ex3
    proc test3(T : typedesc[SomeNumber] = typedesc[float]) : SomeObject[T] =
        echo "type is " & $T
        return SomeObject[T](val : default(0))
    
    #doesn't work: " cannot instantiate: 'SomeNumber' "
    echo test3(int)
    
    Run

Why doesn't the third example work? It looks like the compiler cannot 
instantiate the return type `SomeObject[T]` from a typedesc that's declared as 
`T : typedesc[SomeNumber]`. Otherwise, just returning `T`, as it's the case of 
the first example, works. Also, the second example shows how a fully open 
interface, with `T : typedesc`, seems to work for objects aswell.

Reply via email to