Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #17793 ; improve errmsg when ctor called on non-tyObject kind #17806

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/semobjconstr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

# included from sem.nim

from sugar import dup

type
ObjConstrContext = object
typ: PType # The constructed type
Expand Down Expand Up @@ -389,7 +391,8 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
# multiple times as long as they don't have closures.
result.typ.flags.incl tfHasOwned
if t.kind != tyObject:
return localErrorNode(c, result, "object constructor needs an object type")
return localErrorNode(c, result,
"object constructor needs an object type".dup(addDeclaredLoc(c.config, t)))

# Check if the object is fully initialized by recursively testing each
# field (if this is a case object, initialized fields in two different
Expand Down
2 changes: 1 addition & 1 deletion compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ 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) =
proc addDeclaredLoc*(result: var string, conf: ConfigRef; typ: PType) =
let typ = typ.skipTypes(abstractInst - {tyRange})
result.add " [$1" % typ.kind.toHumanStr
if typ.sym != nil:
Expand Down