RFCs icon indicating copy to clipboard operation
RFCs copied to clipboard

Const section should check for side-effects

Open dom96 opened this issue 7 years ago • 5 comments

import os

const
  foo = getHomeDir() / "asd"

The above code should raise an error.

dom96 avatar Apr 27 '17 09:04 dom96

Well, in this case yes, but I think one may very well want to perform side effects in consts - for instance read something by a configuration file and have it stored in the binary

andreaferretti avatar Apr 27 '17 16:04 andreaferretti

Good point.

Any other ideas on how we could prevent the above gotcha? Simply removing compile-time getHomeDir would work but I'm sure there are cases where it would be useful also.

dom96 avatar Apr 27 '17 17:04 dom96

We can try and make getHomeDir work in the VM but not in a const section, these have separate code paths already iirc. And for now only getHomeDir did bite us.

Araq avatar Apr 27 '17 19:04 Araq

This RFC is stale because it has been open for 1095 days with no activity. Contribute a fix or comment on the issue, or it will be closed in 30 days.

github-actions[bot] avatar Jul 18 '23 02:07 github-actions[bot]

Too useful to close it.

Araq avatar Aug 18 '23 07:08 Araq