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
after reviewing #16962 I tried to double check whether type(x) and typeof(x) have the same behavior (without the typeOfProc arg); it turns out it's not the case:
Example 1
whentrue:
block:
type outType =type(0.0)
echo outType
block:
type outType =typeof(0.0)
echo outType
Current Output
float64
outType
Expected Output
both should behave the same, and both should print float64:
float64
float64
whentrue:
import macros
macrobar(T: typed) =let s = T.getTypeImpl[1]
echo s.typeKind
type outType1 =type(0.0)
type outType2 =typeof(0.0)
bar(outType1)
bar(outType2)
prints:
ntyAlias
ntyFloat
this probably examples Example 1
I'd expect this to print:
ntyFloat
ntyFloat
Example 3
these should be refactored (in semmagic.nim, semtypes.nim):
procsemTypeof2(c: PContext; n: PNode; prev: PType): PType=openScope(c)
var m =BiggestInt1# typeOfIterif n.len ==3:
let mode =semConstExpr(c, n[2])
if mode.kind != nkIntLit:
localError(c.config, n.info, "typeof: cannot evaluate 'mode' parameter at compile-time")
else:
m = mode.intVal
let t =semExprWithType(c, n[1], if m ==1: {efInTypeof} else: {})
closeScope(c)
fixupTypeOf(c, prev, t)
result= t.typ
procsemTypeOf(c: PContext; n: PNode): PNode=var m =BiggestInt1# typeOfIterif n.len ==3:
let mode =semConstExpr(c, n[2])
if mode.kind != nkIntLit:
localError(c.config, n.info, "typeof: cannot evaluate 'mode' parameter at compile-time")
else:
m = mode.intVal
result=newNodeI(nkTypeOfExpr, n.info)
let typExpr =semExprWithType(c, n[1], if m ==1: {efInTypeof} else: {})
result.add typExpr
result.typ =makeTypeDesc(c, typExpr.typ)
Example 4
=> document typeof #16965
the docs for typeof are bad; there should at least be a runnableExamples:
Example 5
this seems un-necessary in semMagic (and seems to pass test suite without it) which is a hot-spot and bypasses normal overload resolution:
of mTypeOf:
markUsed(c, n.info, s)
result=semTypeOf(c, n)
(the other block like this in magicsAfterOverloadResolution seems correct though)
both should behave the same, and both should print float64:
float64
float64
Is outType not supposed to be an alias in both of these situations? Is there supposed to be a special rule where if the RHS is an expression that resolves to a type, no alias is created?
after reviewing #16962 I tried to double check whether type(x) and typeof(x) have the same behavior (without the
typeOfProc
arg); it turns out it's not the case:Current Output
Expected Output
both should behave the same, and both should print
float64
:float64
float64
note that this already prints:
float64
float64
prints:
ntyAlias
ntyFloat
this probably examples Example 1
I'd expect this to print:
ntyFloat
ntyFloat
these should be refactored (in semmagic.nim, semtypes.nim):
Example 4
![image](https://user-images.githubusercontent.com/2194784/107199915-df344180-69ab-11eb-9d24-a321cdc58226.png)
=> document typeof #16965
the docs for
typeof
are bad; there should at least be a runnableExamples:Example 5
this seems un-necessary in
semMagic
(and seems to pass test suite without it) which is a hot-spot and bypasses normal overload resolution:(the other block like this in
magicsAfterOverloadResolution
seems correct though)Additional Information
typeof
was introduced in Regression: 0.18 code with mapIt() fails to compile on 0.19 #9093The text was updated successfully, but these errors were encountered: