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

func keyword for proc types doesn't imply noSideEffect #10838

Closed
cooldome opened this issue Mar 13, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@cooldome
Copy link
Member

commented Mar 13, 2019

The following example compiles while it should not:

type
  MyObject = object
    fn: func(a: int): int

proc myproc(a: int): int =
  echo "bla"  ## Side effect here
  result = a

var a = MyObject(fn: myproc)

Interesting that there is no way for sempass to figure out that fn should no have side effects since:

import macros

dumpTree:
  type
    MyObject = object
      fn: func(a: int): int

returns

StmtList
  TypeSection
    TypeDef
      Ident "MyObject"
      Empty
      ObjectTy
        Empty
        Empty
        RecList
          IdentDefs
            Ident "fn"
            ProcTy   ## interesting line
              FormalParams
                Ident "int"
                IdentDefs
                  Ident "a"
                  Ident "int"
                  Empty
              Empty
            Empty

The relevant information is already lost in the parser. I will provide a fix.

@cooldome cooldome added the Parser label Mar 13, 2019

cooldome added a commit to cooldome/Nim that referenced this issue Mar 13, 2019

@Araq Araq closed this in c19cd14 Mar 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.