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

fix(dojo-lang): raise an error on value before key in model #2891

Merged
merged 9 commits into from
Jan 16, 2025
18 changes: 17 additions & 1 deletion crates/dojo/lang/src/attribute_macros/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@
members: &[MemberAst],
diagnostics: &mut Vec<PluginDiagnostic>,
) -> Vec<Member> {
let mut keys = true;

Check warning on line 44 in crates/dojo/lang/src/attribute_macros/element.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/lang/src/attribute_macros/element.rs#L44

Added line #L44 was not covered by tests
glihm marked this conversation as resolved.
Show resolved Hide resolved
members
.iter()
.filter_map(|member_ast| {
let key = member_ast.has_attr(db, "key");
glihm marked this conversation as resolved.
Show resolved Hide resolved

Check warning on line 49 in crates/dojo/lang/src/attribute_macros/element.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/lang/src/attribute_macros/element.rs#L48-L49

Added lines #L48 - L49 were not covered by tests
let member = Member {
name: member_ast.name(db).text(db).to_string(),
ty: member_ast
Expand All @@ -53,10 +56,23 @@
.get_text(db)
.trim()
.to_string(),
key: member_ast.has_attr(db, "key"),
key,

Check warning on line 59 in crates/dojo/lang/src/attribute_macros/element.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/lang/src/attribute_macros/element.rs#L59

Added line #L59 was not covered by tests
};

// validate key member
if key {
if !keys {
diagnostics.push(PluginDiagnostic {
message: "Key members must be defined before non-key members.".into(),
stable_ptr: member_ast.name(db).stable_ptr().untyped(),
severity: Severity::Error,
});
return None;
}
} else {
keys = false;
}

Check warning on line 74 in crates/dojo/lang/src/attribute_macros/element.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/lang/src/attribute_macros/element.rs#L63-L74

Added lines #L63 - L74 were not covered by tests

if member.key && member.ty == "u256" {
diagnostics.push(PluginDiagnostic {
message: "Key is only supported for core types that are 1 felt long once \
Expand Down
Loading