fixes #13646
This commit is contained in:
parent
3a6b470412
commit
a102eb5ef6
3 changed files with 34 additions and 6 deletions
|
|
@ -232,13 +232,14 @@ proc semConv(c: PContext, n: PNode): PNode =
|
||||||
result = newNodeI(nkConv, n.info)
|
result = newNodeI(nkConv, n.info)
|
||||||
|
|
||||||
var targetType = semTypeNode(c, n[0], nil)
|
var targetType = semTypeNode(c, n[0], nil)
|
||||||
if targetType.kind == tyTypeDesc:
|
case targetType.kind
|
||||||
|
of tyTypeDesc:
|
||||||
internalAssert c.config, targetType.len > 0
|
internalAssert c.config, targetType.len > 0
|
||||||
if targetType.base.kind == tyNone:
|
if targetType.base.kind == tyNone:
|
||||||
return semTypeOf(c, n)
|
return semTypeOf(c, n)
|
||||||
else:
|
else:
|
||||||
targetType = targetType.base
|
targetType = targetType.base
|
||||||
elif targetType.kind == tyStatic:
|
of tyStatic:
|
||||||
var evaluated = semStaticExpr(c, n[1])
|
var evaluated = semStaticExpr(c, n[1])
|
||||||
if evaluated.kind == nkType or evaluated.typ.kind == tyTypeDesc:
|
if evaluated.kind == nkType or evaluated.typ.kind == tyTypeDesc:
|
||||||
result = n
|
result = n
|
||||||
|
|
@ -248,6 +249,7 @@ proc semConv(c: PContext, n: PNode): PNode =
|
||||||
return evaluated
|
return evaluated
|
||||||
else:
|
else:
|
||||||
targetType = targetType.base
|
targetType = targetType.base
|
||||||
|
else: discard
|
||||||
|
|
||||||
maybeLiftType(targetType, c, n[0].info)
|
maybeLiftType(targetType, c, n[0].info)
|
||||||
|
|
||||||
|
|
@ -268,7 +270,7 @@ proc semConv(c: PContext, n: PNode): PNode =
|
||||||
targetType.skipTypes(abstractPtrs).kind == tyObject:
|
targetType.skipTypes(abstractPtrs).kind == tyObject:
|
||||||
localError(c.config, n.info, "object construction uses ':', not '='")
|
localError(c.config, n.info, "object construction uses ':', not '='")
|
||||||
var op = semExprWithType(c, n[1])
|
var op = semExprWithType(c, n[1])
|
||||||
if targetType.isMetaType:
|
if targetType.kind != tyGenericParam and targetType.isMetaType:
|
||||||
let final = inferWithMetatype(c, targetType, op, true)
|
let final = inferWithMetatype(c, targetType, op, true)
|
||||||
result.add final
|
result.add final
|
||||||
result.typ = final.typ
|
result.typ = final.typ
|
||||||
|
|
@ -279,6 +281,10 @@ proc semConv(c: PContext, n: PNode): PNode =
|
||||||
# here or needs to be overwritten too then.
|
# here or needs to be overwritten too then.
|
||||||
result.add op
|
result.add op
|
||||||
|
|
||||||
|
if targetType.kind == tyGenericParam:
|
||||||
|
result.typ = makeTypeFromExpr(c, copyTree(result))
|
||||||
|
return result
|
||||||
|
|
||||||
if not isSymChoice(op):
|
if not isSymChoice(op):
|
||||||
let status = checkConvertible(c, result.typ, op)
|
let status = checkConvertible(c, result.typ, op)
|
||||||
case status
|
case status
|
||||||
|
|
|
||||||
|
|
@ -618,6 +618,9 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||||
eraseVoidParams(result)
|
eraseVoidParams(result)
|
||||||
skipIntLiteralParams(result)
|
skipIntLiteralParams(result)
|
||||||
|
|
||||||
|
of tyRange:
|
||||||
|
result[0] = result[0].skipTypes({tyStatic, tyDistinct})
|
||||||
|
|
||||||
else: discard
|
else: discard
|
||||||
else:
|
else:
|
||||||
# If this type doesn't refer to a generic type we may still want to run it
|
# If this type doesn't refer to a generic type we may still want to run it
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
|
discard """
|
||||||
|
output: '''[1, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
CTBool[Ct[system.uint32]]'''
|
||||||
|
"""
|
||||||
|
|
||||||
block tconstraints:
|
block tconstraints:
|
||||||
proc myGenericProc[T: object|tuple|int|ptr|ref|distinct](x: T): string =
|
proc myGenericProc[T: object|tuple|int|ptr|ref|distinct](x: T): string =
|
||||||
|
|
@ -46,4 +49,20 @@ block tprocbothmeta:
|
||||||
assert myMap(@[1,2,3], myFun) == @[11.0, 12.0, 13.0]
|
assert myMap(@[1,2,3], myFun) == @[11.0, 12.0, 13.0]
|
||||||
|
|
||||||
|
|
||||||
|
# https://github.com/nim-lang/Nim/issues/13646
|
||||||
|
|
||||||
|
type
|
||||||
|
BaseUint* = SomeUnsignedInt or byte
|
||||||
|
Ct*[T] = distinct T
|
||||||
|
## Constant-Time wrapper
|
||||||
|
## Only constant-time operations in particular the ternary operator equivalent
|
||||||
|
## condition: if true: a else: b
|
||||||
|
## are allowed
|
||||||
|
|
||||||
|
CTBool*[T] = distinct range[T(0)..T(1)]
|
||||||
|
## Constant-Time boolean wrapper
|
||||||
|
|
||||||
|
var x: array[8, CTBool[Ct[uint32]]]
|
||||||
|
x[0] = (CTBool[Ct[uint32]])(1)
|
||||||
|
echo x.repr, " ", typeof(x[0])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue