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

Allow using pure functions in assignment to constant variables #3122

Closed
joeykrug opened this issue Oct 22, 2017 · 6 comments
Closed

Allow using pure functions in assignment to constant variables #3122

joeykrug opened this issue Oct 22, 2017 · 6 comments
Labels
language design :rage4: Any changes to the language, e.g. new features stale The issue/PR was marked as stale because it has been open for too long.

Comments

@joeykrug
Copy link

E               /home/ubuntu/workspace/tests/solidity_test_helpers/Constants.sol:34:45: TypeError: Initial value for constant variable has to be compile-time constant.
E                   uint256 public constant GAS_TO_REPORT = Reporting.gasToReport();

I have a contract I'm trying to compile that imports another contract with a pure / constant function as below:

    uint256 private constant GAS_TO_REPORT = 600000;

    function gasToReport() internal pure returns (uint256) { return GAS_TO_REPORT; }

Any idea why it's saying Initial value for constant variable has to be compile-time constant. for this line: uint256 public constant GAS_TO_REPORT = Reporting.gasToReport(); ?

@axic
Copy link
Member

axic commented Oct 22, 2017

Only a limited set of expressions are accepted as "pure" for compile-time constants and currently pure functions are not part of that.

Though it may be feasible lifting that restriction since we have a visibility checker in place now, though I would rather opt to restrict it even further (sha256/ripemd160 is part of it, yet it will compiled into a call and that is counterintuitive).

@axic
Copy link
Member

axic commented Oct 30, 2017

I'd argue against allowing any pure function in constant variables before #3157 is sorted out.

@axic axic added the feature label Oct 30, 2017
@axic axic changed the title Experimental Pragma Issue Allow using pure functions in assignment to constant variables Oct 30, 2017
@axic axic added the language design :rage4: Any changes to the language, e.g. new features label Jul 28, 2018
@k06a
Copy link

k06a commented Jul 25, 2022

Any progress on this?

@cameel
Copy link
Member

cameel commented Jul 26, 2022

The current status is that this depends on #3157, and that one first needs some design decisions from @ekpyron. It's one of our roadmap goals for this year, but we also have immutable reference types on the roadmap and I think @ekpyron will be working on them first.

The question is also how breaking it will be. Changing how pure works would definitely be breaking and would have to be scheduled for 0.9.0. But I think we're more likely to leave pure as is and introduce a new mutability level for functions that can be evaluated at compilation time and I think could be done in 0.8.x.

@github-actions
Copy link

This issue has been marked as stale due to inactivity for the last 90 days.
It will be automatically closed in 7 days.

@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Feb 13, 2023
@ekpyron
Copy link
Member

ekpyron commented Feb 13, 2023

I'm closing this as part of #13724, resp. #3157

@ekpyron ekpyron closed this as completed Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language design :rage4: Any changes to the language, e.g. new features stale The issue/PR was marked as stale because it has been open for too long.
Projects
None yet
Development

No branches or pull requests

6 participants