Skip to content

Commit 2460c83

Browse files
committed
fmt
1 parent 8d97223 commit 2460c83

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

src/codegen/generators/data_type_generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ impl<'ink> DataTypeGenerator<'ink, '_> {
366366
Some(v) => Ok((it.get_qualified_name(), v)),
367367
None => self
368368
.types_index
369-
.get_associated_type(it.get_type_name())
370-
.map(get_default_for)
369+
.get_associated_type(it.get_type_name())
370+
.map(get_default_for)
371371
.map(|v| (it.get_qualified_name(), v)),
372372
})
373373
})

src/parser.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,9 @@ fn parse_string_size_expression(lexer: &mut ParseSession) -> Option<AstNode> {
11051105
.with_location(error_range)
11061106
.with_error_code("E009"),
11071107
);
1108-
} else if !is_enum_like && (opening_token == KeywordParensOpen || lexer.token == KeywordParensClose) {
1108+
} else if !is_enum_like
1109+
&& (opening_token == KeywordParensOpen || lexer.token == KeywordParensClose)
1110+
{
11091111
lexer.accept_diagnostic(Diagnostic::new(
11101112
"Unusual type of parentheses around string size expression, consider using square parentheses '[]'").
11111113
with_location(error_range)
@@ -1135,21 +1137,14 @@ fn parse_string_type_definition(
11351137

11361138
// Check if this is actually an enum type (e.g., STRING (a := 1, b := 2))
11371139
// If size is an ExpressionList with assignments, it's likely an invalid enum definition
1138-
let is_enum_like = matches!(
1139-
&size,
1140-
Some(AstNode { stmt: AstStatement::ExpressionList(_), .. })
1141-
);
1140+
let is_enum_like = matches!(&size, Some(AstNode { stmt: AstStatement::ExpressionList(_), .. }));
11421141

11431142
match (size, &name, is_enum_like) {
11441143
(Some(size), _, true) => {
11451144
// This looks like an enum definition with STRING/WSTRING as the type
11461145
// Create an EnumType so validation can catch it as invalid
11471146
Some(DataTypeDeclaration::Definition {
1148-
data_type: Box::new(DataType::EnumType {
1149-
name,
1150-
numeric_type: text,
1151-
elements: size,
1152-
}),
1147+
data_type: Box::new(DataType::EnumType { name, numeric_type: text, elements: size }),
11531148
location,
11541149
scope: lexer.scope.clone(),
11551150
})
@@ -1189,11 +1184,8 @@ fn parse_enum_type_definition(
11891184

11901185
// Check for Codesys-style type specification after the enum list
11911186
// TYPE COLOR : (...) DWORD;
1192-
let numeric_type = if lexer.token == Identifier {
1193-
lexer.slice_and_advance()
1194-
} else {
1195-
DINT_TYPE.to_string()
1196-
};
1187+
let numeric_type =
1188+
if lexer.token == Identifier { lexer.slice_and_advance() } else { DINT_TYPE.to_string() };
11971189

11981190
let initializer = lexer.try_consume(KeywordAssignment).then(|| parse_expression(lexer));
11991191
Some((

src/resolver.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,14 @@ impl TypeAnnotator<'_> {
389389
}
390390
// Enum types need to be promoted based on their underlying integer type
391391
DataTypeInformation::Enum { referenced_type, .. } => {
392-
let enum_base_type = self.index.get_effective_type_or_void_by_name(referenced_type);
393-
if let DataTypeInformation::Integer { .. } = enum_base_type.get_type_information() {
394-
if !enum_base_type.information.is_bool() && !enum_base_type.information.is_character() {
392+
let enum_base_type =
393+
self.index.get_effective_type_or_void_by_name(referenced_type);
394+
if let DataTypeInformation::Integer { .. } =
395+
enum_base_type.get_type_information()
396+
{
397+
if !enum_base_type.information.is_bool()
398+
&& !enum_base_type.information.is_character()
399+
{
395400
get_bigger_type(
396401
enum_base_type,
397402
self.index.get_type_or_panic(DINT_TYPE),

src/validation/tests/enum_validation_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fn type_name_used_as_value() {
416416
END_PROGRAM
417417
",
418418
);
419-
419+
420420
assert!(diagnostics.len() > 0);
421421
assert_snapshot!(diagnostics, @r#""#);
422422
}

src/validation/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ pub fn visit_data_type<T: AnnotationMap>(
5454
.with_location(location),
5555
);
5656
}
57-
}
58-
else {
57+
} else {
5958
validator.push_diagnostic(Diagnostic::unknown_type(numeric_type, location));
6059
}
6160
}

0 commit comments

Comments
 (0)