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

Support untyped enum declaration #902

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

taichi-ishitani
Copy link
Contributor

resolve #539

@taichi-ishitani taichi-ishitani force-pushed the typeless_enum branch 3 times, most recently from 982fb8b to 369d3f7 Compare August 21, 2024 09:24
} else {
// TODO:
// report error
unreachable!();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally unreachable! is used for "this statement is unreachable logically".
If reporting error is required in the future, todo!("report error"); is better.

@@ -626,6 +662,8 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> {
if let Some(namespace) = namespace {
self.namespace.push(namespace);
}

self.enum_member_value = Some(value.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

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

clone is not required because value is not used after this statement.

@@ -458,12 +458,16 @@ impl fmt::Display for SymbolKind {
format!("typedef alias ({})", x.r#type)
}
SymbolKind::Enum(x) => {
format!("enum ({})", x.r#type)
if x.r#type.is_some() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using if let Some is more idiomatic.

if let Some(ref x) = x.r#type {
    format!("enum ({})", x)
} else {


fn default_enum_type(&mut self, arg: &EnumDeclaration) {
let enum_symbol = symbol_table::resolve(arg.identifier.as_ref())
.unwrap()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This unwrap may be troublesome.
If there is any error around symbol table, this resolve may be failed.
So Veryl compiler may panic before reporting these errors.

if let SymbolKind::EnumMember(member) = member_symbol.kind {
match member.value {
EnumMemberValue::ExplicitValue(_expression, evaluated) => {
if evaluated.is_some() && evaluated.unwrap() > max_value {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you use if let Some?

@taichi-ishitani
Copy link
Contributor Author

I fixed all review feedbacks.

@dalance
Copy link
Collaborator

dalance commented Aug 22, 2024

Looks good.
Thanks!

@dalance dalance merged commit 42af9a0 into veryl-lang:master Aug 22, 2024
6 checks passed
@dalance dalance added the enhancement New feature or request label Aug 22, 2024
@taichi-ishitani taichi-ishitani deleted the typeless_enum branch August 22, 2024 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] untyped enum type
2 participants