mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
* fix #10053 FieldError for vm * fixup * FieldError now also shows runtime value of discriminant * fix field error reporting in vm * also report culprit line info in err msg * fix errors for newruntime 2 * fix for js * fixup * PRTEMP4 * works * works * works perfect * refactor * std/private/repr_impl * suppport --gc:arc * cleanup * refactor * simplify * simplify * simplify * fixup * move out compiler.vmgen.genCustom * fixup * fixup * add tests * revert compiler/debugutils.nim * simplify reprDiscriminant * fixup * lib/std/private/repr_impl.nim -> lib/system/repr_impl.nim * try to fix D20210812T165220 * honor --declaredlocs * control toFileLineCol via --declaredlocs
40 lines
1.7 KiB
Nim
40 lines
1.7 KiB
Nim
# this module avoids ast depending on msgs or vice versa
|
|
import std/strutils
|
|
import options, ast, msgs
|
|
|
|
proc typSym*(t: PType): PSym =
|
|
result = t.sym
|
|
if result == nil and t.kind == tyGenericInst: # this might need to be refined
|
|
result = t[0].sym
|
|
|
|
proc addDeclaredLoc*(result: var string, conf: ConfigRef; sym: PSym) =
|
|
result.add " [$1 declared in $2]" % [sym.kind.toHumanStr, toFileLineCol(conf, sym.info)]
|
|
|
|
proc addDeclaredLocMaybe*(result: var string, conf: ConfigRef; sym: PSym) =
|
|
if optDeclaredLocs in conf.globalOptions and sym != nil:
|
|
addDeclaredLoc(result, conf, sym)
|
|
|
|
proc addDeclaredLoc*(result: var string, conf: ConfigRef; typ: PType) =
|
|
# xxx figure out how to resolve `tyGenericParam`, e.g. for
|
|
# proc fn[T](a: T, b: T) = discard
|
|
# fn(1.1, "a")
|
|
let typ = typ.skipTypes(abstractInst + {tyStatic, tySequence, tyArray, tySet, tyUserTypeClassInst, tyVar, tyRef, tyPtr} - {tyRange})
|
|
result.add " [$1" % typ.kind.toHumanStr
|
|
if typ.sym != nil:
|
|
result.add " declared in " & toFileLineCol(conf, typ.sym.info)
|
|
result.add "]"
|
|
|
|
proc addDeclaredLocMaybe*(result: var string, conf: ConfigRef; typ: PType) =
|
|
if optDeclaredLocs in conf.globalOptions: addDeclaredLoc(result, conf, typ)
|
|
|
|
template quoteExpr*(a: string): untyped =
|
|
## can be used for quoting expressions in error msgs.
|
|
"'" & a & "'"
|
|
|
|
proc genFieldDefect*(conf: ConfigRef, field: string, disc: PSym): string =
|
|
let obj = disc.owner.name.s # `types.typeToString` might be better, eg for generics
|
|
result = "field '$#' is not accessible for type '$#'" % [field, obj]
|
|
if optDeclaredLocs in conf.globalOptions:
|
|
result.add " [discriminant declared in $#]" % toFileLineCol(conf, disc.info)
|
|
result.add " using '$# = " % disc.name.s
|