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

Codegen error for base type pointer access; missing pointer dereference #15692

Open
haxscramper opened this issue Oct 23, 2020 · 1 comment
Open

Comments

@haxscramper
Copy link
Contributor

Following code

type
  Base = ref object of RootObj
    fld1: int

  Derived = ref object of Base
    fld2: string


block:
  proc newBase(val: var Base) =
    if val == nil: new(val)
    val.fld1 = 12

  proc newBase(): Base = newBase(result)

  proc newDerived(val: var Derived) =
    if val == nil: new(val)
    val.fld2 = "somefield"
    newBase Base(val)

  proc newDerived(): Derived = newDerived(result)

  echo newDerived()[]
  echo newBase()[]

Current Output

Results in C codegen error (type hashes removed for redability).

error: member reference base type 'tyObject_DerivedcolonObjectType *' (aka 'struct tyObject_DerivedcolonObjectType *') is not a structure or union
        T5_ = &val->Sup;

In particular, error is generated for the line T5_ = &val->Sup; and can be fixed by manually editing it to T5_ = &((*val)->Sup);.

Issue persists for all nim versions that I tried (via playground), my particular version is

$ nim -v
Nim Compiler Version 1.4.0 [Linux: amd64]
Compiled at 2020-10-16
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: bdcd87afca238a0a7b2c70971827cf9172817b12
active boot switches: -d:release -d:danger
@timotheecour
Copy link
Member

Can you edit the title to something less generic?

@haxscramper haxscramper changed the title Codegen error Codegen error for base type pointer access; missing pointer dereference Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants