-
Notifications
You must be signed in to change notification settings - Fork 187
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
Reject zero type when declare event fields #774
base: master
Are you sure you want to change the base?
Changes from 2 commits
4651a67
b44d65d
b589fc8
a1f11d0
851c7b0
5aa0254
3e5f7a5
e271b56
1db7920
811b45a
382d3a0
9131fce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,9 @@ impl TypeId { | |
pub fn is_base(&self, db: &dyn AnalyzerDb) -> bool { | ||
self.typ(db).is_base() | ||
} | ||
pub fn is_zero_size(&self, db: &dyn AnalyzerDb) -> bool { | ||
self.typ(db).is_zero_size(db) | ||
} | ||
pub fn is_bool(&self, db: &dyn AnalyzerDb) -> bool { | ||
matches!(self.typ(db), Type::Base(Base::Bool)) | ||
} | ||
|
@@ -494,6 +497,14 @@ impl Type { | |
false | ||
} | ||
|
||
pub fn is_zero_size(&self, db: &dyn AnalyzerDb) -> bool { | ||
match &self { | ||
Type::Base(Base::Unit) => true, | ||
Type::Contract(inner) => inner.fields(db).is_empty(), | ||
Type::Struct(inner) => inner.fields(db).is_empty(), | ||
_ => false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Example.
Also, other types can be zero-sized.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I create salsa query |
||
} | ||
} | ||
/// Creates an instance of bool. | ||
pub fn bool() -> Self { | ||
Type::Base(Base::Bool) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
source: crates/analyzer/tests/errors.rs | ||
expression: "error_string(&path, test_files::fixture(path))" | ||
--- | ||
error: event field type must have a non-zero types | ||
┌─ compile_errors/invalid_type_in_event_zero_sized.fe:8:8 | ||
│ | ||
8 │ x: () | ||
│ ^^ this type can't be used as an event field | ||
|
||
error: event field type must have a non-zero types | ||
┌─ compile_errors/invalid_type_in_event_zero_sized.fe:9:8 | ||
│ | ||
9 │ y: EmptyStruct | ||
│ ^^^^^^^^^^^ this type can't be used as an event field | ||
|
||
error: event field type must have a non-zero types | ||
┌─ compile_errors/invalid_type_in_event_zero_sized.fe:10:8 | ||
│ | ||
10 │ z: EmptyContract | ||
│ ^^^^^^^^^^^^^ this type can't be used as an event field | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
contract EmptyContract { | ||
} | ||
|
||
struct EmptyStruct { | ||
} | ||
|
||
event Event { | ||
x: () | ||
y: EmptyStruct | ||
z: EmptyContract | ||
} |
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.
There is no need to reject all zero-sized fields. It'd be better to reject a field iff its type is zero-sized and it is indexed.
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.
Done