In my function to make wFont for 
[https://khchen.github.io/wNim/](https://khchen.github.io/wNim/), the following 
2 can work 
    
    
    import wNim
    
    proc makeFont1(fontMessage: int): wFont {.discardable.}=
        var
            fontTmpMessage: wFont = Font(12, weight=wFontWeightBold)
        
        echo fontMessage is float
        echo fontMessage is int
        echo fontMessage is wFont
        
        if (fontMessage is float) or (fontMessage is int) :
            echo "in if"
            fontTmpMessage = Font(float fontMessage, weight=wFontWeightBold)
        
        return fontTmpMessage
    
    
    proc makeFont2(fontMessage:wFont): wFont {.discardable.}=
        var
            fontTmpMessage: wFont = Font(12, weight=wFontWeightBold)
        
        echo fontMessage is float
        echo fontMessage is int
        echo fontMessage is wFont
        
        if (fontMessage is wFont):
            echo "in if"
            fontTmpMessage = fontMessage
        
        return fontTmpMessage
    
    
    echo makeFont1(20).getPointSize()
    echo "\n"
    
    echo makeFont2(Font(32, weight=wFontWeightBold)).getPointSize()
    echo "\n"
    
    
    Run

But when I try to combine the above into one in which the argument can be a 
number of the font size, or wFont. 
    
    
    import wNim
    
    proc makeFont3(fontMessage: int|wFont): wFont {.discardable.}=
        var
            fontTmpMessage: wFont = Font(12, weight=wFontWeightBold)
        
        echo fontMessage is float
        echo fontMessage is int
        echo fontMessage is wFont
        
        if (fontMessage is float) or (fontMessage is int) :
            fontTmpMessage = Font(float fontMessage, weight=wFontWeightBold)
        else:
            fontTmpMessage = fontMessage
    
    echo makeFont3(40).getPointSize()
    echo "\n"
    
    echo makeFont3(Font(45, weight=wFontWeightBold)).getPointSize()
    echo "\n"
    
    
    Run

says 
    
    
    b2.nim(16, 15) template/generic instantiation of `makeFont3` from here
    b2.nim(14, 24) Error: type mismatch: got <int> but expected 'wFont = ref 
wFont:ObjectType'
    
    
    
    Run

Reply via email to