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

Represent type(f) correctly in the ast #1609

Merged
merged 6 commits into from
Dec 16, 2023

Conversation

seanyoung
Copy link
Contributor

@seanyoung seanyoung commented Dec 12, 2023

This makes the ast correct, and also the following code is now parsed correctly:

        function foo() {
                type(int);
        }

type(enum-type).min or type(enum).min is now supported.

This fixes all the issues wrt type(T) in the solc tests.

This makes the ast correct, and also the following code is now parsed
correctly:

	function foo() {
		type(int);
	}

Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Sean Young <sean@mess.org>
Copy link

codecov bot commented Dec 12, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (68b59a4) 87.94% compared to head (e2819a3) 88.14%.

Files Patch % Lines
src/codegen/expression.rs 82.14% 5 Missing ⚠️
src/sema/eval.rs 85.00% 3 Missing ⚠️
src/sema/expression/member_access.rs 98.38% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1609      +/-   ##
==========================================
+ Coverage   87.94%   88.14%   +0.19%     
==========================================
  Files         137      137              
  Lines       65902    65992      +90     
==========================================
+ Hits        57959    58166     +207     
+ Misses       7943     7826     -117     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Sean Young <sean@mess.org>
src/codegen/expression.rs Outdated Show resolved Hide resolved
Comment on lines +2281 to +2285
ast::Builtin::TypeRuntimeCode | ast::Builtin::TypeCreatorCode => {
let ast::Expression::TypeOperator {
ty: Type::Contract(contract_no),
..
} = &args[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a builtin, wouldn't it be nicer of item we access from a type operator was a member access? This way you could define the possible members for the operator.

I found it somewhat uncomfortable that you require the argument to be TypeOperator in all cases with an unreachable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is a constraint for the argument, perhaps it could be enforced in another way that avoids the unreachable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by member access? Expression::StructMember? That expression is not suitable, it takes a field number and it has "Struct" in its name.

You may want the location of type(..) in type(int) . min and type(int) can be free standing too, so a separate Expression::TypeOperator enum makes sense to me.

Please make suggestions because I have no idea.

let mut creates = Vec::new();
let mut diagnostics = Diagnostics::default();

swap(&mut creates, &mut ns.contracts[contract_no].creates);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the swap necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

borrow checker

Co-authored-by: Lucas Steuernagel <38472950+LucasSte@users.noreply.github.com>
Signed-off-by: Sean Young <sean@mess.org>
@seanyoung
Copy link
Contributor Author

If there are no further comments, I'll merge

@seanyoung seanyoung merged commit 92a6c6c into hyperledger:main Dec 16, 2023
20 checks passed
@seanyoung seanyoung deleted the type-operator branch December 16, 2023 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants