mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 14:25:23 +00:00
fixes fieldDefect loses enum type info in ORC; consistent with VM and refc (#21954)
fixes fieldDefect loses enum type info in ORC
This commit is contained in:
@@ -933,10 +933,17 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) =
|
||||
var discIndex = newRopeAppender()
|
||||
rdSetElemLoc(p.config, v, u.t, discIndex)
|
||||
if optTinyRtti in p.config.globalOptions:
|
||||
# not sure how to use `genEnumToStr` here
|
||||
if p.config.getStdlibVersion < (1, 5, 1):
|
||||
const code = "{ #raiseFieldError($1); "
|
||||
linefmt(p, cpsStmts, code, [strLit])
|
||||
let base = disc.typ.skipTypes(abstractInst+{tyRange})
|
||||
case base.kind
|
||||
of tyEnum:
|
||||
const code = "{ #raiseFieldErrorStr($1, $2); "
|
||||
let toStrProc = getToStringProc(p.module.g.graph, base)
|
||||
# XXX need to modify this logic for IC.
|
||||
# need to analyze nkFieldCheckedExpr and marks procs "used" like range checks in dce
|
||||
var toStr: TLoc
|
||||
expr(p, newSymNode(toStrProc), toStr)
|
||||
let enumStr = "$1($2)" % [rdLoc(toStr), rdLoc(v)]
|
||||
linefmt(p, cpsStmts, code, [strLit, enumStr])
|
||||
else:
|
||||
const code = "{ #raiseFieldError2($1, (NI)$2); "
|
||||
linefmt(p, cpsStmts, code, [strLit, discIndex])
|
||||
@@ -947,12 +954,8 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) =
|
||||
var firstLit = newRopeAppender()
|
||||
int64Literal(cast[int](first), firstLit)
|
||||
let discName = genTypeInfo(p.config, p.module, disc.sym.typ, e.info)
|
||||
if p.config.getStdlibVersion < (1,5,1):
|
||||
const code = "{ #raiseFieldError($1); "
|
||||
linefmt(p, cpsStmts, code, [strLit])
|
||||
else:
|
||||
const code = "{ #raiseFieldError2($1, #reprDiscriminant(((NI)$2) + (NI)$3, $4)); "
|
||||
linefmt(p, cpsStmts, code, [strLit, discIndex, firstLit, discName])
|
||||
const code = "{ #raiseFieldError2($1, #reprDiscriminant(((NI)$2) + (NI)$3, $4)); "
|
||||
linefmt(p, cpsStmts, code, [strLit, discIndex, firstLit, discName])
|
||||
|
||||
raiseInstr(p, p.s(cpsStmts))
|
||||
linefmt p, cpsStmts, "}$n", []
|
||||
|
||||
@@ -38,6 +38,10 @@ when defined(nimV2):
|
||||
proc raiseFieldError2(f: string, discVal: int) {.compilerproc, noinline.} =
|
||||
## raised when field is inaccessible given runtime value of discriminant
|
||||
sysFatal(FieldDefect, f & $discVal & "'")
|
||||
|
||||
proc raiseFieldErrorStr(f: string, discVal: string) {.compilerproc, noinline.} =
|
||||
## raised when field is inaccessible given runtime value of discriminant
|
||||
sysFatal(FieldDefect, formatFieldDefect(f, discVal))
|
||||
else:
|
||||
proc raiseFieldError2(f: string, discVal: string) {.compilerproc, noinline.} =
|
||||
## raised when field is inaccessible given runtime value of discriminant
|
||||
|
||||
@@ -434,7 +434,6 @@ mused3.nim(75, 10) Hint: duplicate import of 'mused3a'; previous import here: mu
|
||||
fn("-d:case2 --gc:refc"): """mfield_defect.nim(25, 15) field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'"""
|
||||
fn("-d:case1 -b:js"): """mfield_defect.nim(25, 15) Error: field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'"""
|
||||
fn("-d:case2 -b:js"): """field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'"""
|
||||
# 3 instead of k3, because of lack of RTTI
|
||||
fn("-d:case2 --gc:arc"): """mfield_defect.nim(25, 15) field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = 3'"""
|
||||
fn("-d:case2 --gc:arc"): """mfield_defect.nim(25, 15) field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'"""
|
||||
else:
|
||||
discard # only during debugging, tests added here will run with `-d:nimTestsTrunnerDebugging` enabled
|
||||
|
||||
Reference in New Issue
Block a user