-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
typeof(a[0]) in proc return type gives: Error: type mismatch
Example
# proc fn[T](a: T, index: int): typeof(a.x) = a.x # ok
proc fn2(a: seq[int], index: int): typeof(a[0]) = a[index] # ok
# proc fn[T](a: T, index: int): typeof(a[0]) = a[index] # Error: type mismatch: got <T, int literal(0)>
Current Output
Error: type mismatch: got <T, int literal(0)>
Expected Output
works
Additional Information
05384ef 1.3.5 devel
note
I'm wondering if it's due to the way []
is hardcoded in compiler in a few places eg:
semArrGet:
x[0] = newIdentNode(getIdent(c.cache, "[]"), n.info)
of nkCallKinds:
# builtin slice keeps lvalue-ness:
if getMagic(n) in {mArrGet, mSlice}:
result = isAssignable(owner, n[1], isUnsafeAddr)
proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
if m.magic in {mArrGet, mArrPut}:
elif op.name.s == "[]" and op.fromSystem:
let slice = n[2].skipStmtList
c.addSlice(n, n[1], slice[1], slice[2])
analyseSons(c, n)
elif op.name.s == "[]=" and op.fromSystem:
let slice = n[2].skipStmtList
c.addSlice(n, n[1], slice[1], slice[2])
analyseSons(c, n)
if ident != nil and ident.s == "[]":