-
-
Notifications
You must be signed in to change notification settings - Fork 793
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
feat: allow constant and immutable variables to be declared public #3024
Conversation
vyper/ast/nodes.py
Outdated
( | ||
i.func.id | ||
for i in self.annotation.get_children( | ||
Call, filters={"func.id": {"immutable", "constant"}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is weird. you might be able to have some weird combination like public(immutable(constant(...)))
vyper/codegen/expr.py
Outdated
@@ -260,6 +260,12 @@ def parse_Attribute(self): | |||
elif isinstance(self.expr.value, vy_ast.Name) and self.expr.value.id == "self": | |||
type_ = self.expr._metadata["type"] | |||
var = self.context.globals[self.expr.attr] | |||
# handle public(immutable) variables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once the expansion is fixed for immutables, i don't think there will be any need for any codegen changes
Codecov Report
@@ Coverage Diff @@
## master #3024 +/- ##
==========================================
+ Coverage 88.30% 88.34% +0.04%
==========================================
Files 97 98 +1
Lines 10941 11021 +80
Branches 2587 2605 +18
==========================================
+ Hits 9661 9737 +76
- Misses 831 833 +2
- Partials 449 451 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
by the way, i think that only handling |
512113d
to
6ecc427
Compare
6ecc427
to
9000079
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is looking pretty good. it looks like there is a test case failing which expects public()
to throw an ArgumentException
but it fails with an index OOB instead.
31db633
to
4d1ca85
Compare
vyper/ast/nodes.py
Outdated
@@ -1290,6 +1291,14 @@ def __init__(self, *args, **kwargs): | |||
elif call_name == "public": | |||
# declaring a public variable | |||
self.is_public = True | |||
# handle the cases where a constant or immutable variable is public | |||
if not len(self.annotation.args): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not len(self.annotation.args): | |
# do the same thing as `validate_call_args` | |
# (can't be imported due to cyclic dependency) | |
if len(self.annotation.args) != 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also can you remove the corresponding dead code in vyper/semantics/validation/module.py?
Nice |
@benber86 i cleaned up the logic for extracting the public/immutable/constant annotations a little bit |
This pull request introduces 2 alerts when merging 062ffb8 into 915d430 - view on LGTM.com new alerts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs dynamic tests showing the constant is made available as a public method
What I did
I gave a first try to #2903 after encountering the same issue and discussing it on Discord. This will make it possible to declare
immutable
andconstant
variables aspublic
.This is still a WIP as:
self
, but this should probably be done separately.public(immutable(x))
orpublic(constant(x))
notimmutable(public(x))
orconstant(public(x))
How I did it
is_immutable
oris_constant
accordinglyimmutable
andconstant
variablesHow to verify it
tests/parser/syntax/test_public.py
Commit message
Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)
Description for the changelog
Cute Animal Picture