fix comptime variable errors

This commit is contained in:
Moritz Hölting 2025-08-13 18:24:48 +02:00
parent 15dde037b7
commit e0c3253ab6
2 changed files with 21 additions and 7 deletions

View File

@ -706,13 +706,14 @@ impl Primary {
_ => false, _ => false,
}, },
Self::MemberAccess(_) => { Self::MemberAccess(_) => {
// TODO: // TODO: correct return value after check
true true
} }
Self::Identifier(ident) => match scope.get_variable(ident.span.str()) { Self::Identifier(ident) => match scope.get_variable(ident.span.str()) {
Some(VariableType::BooleanStorage) => expected == ValueType::Boolean, Some(VariableType::BooleanStorage) => expected == ValueType::Boolean,
Some(VariableType::ScoreboardValue) => expected == ValueType::Integer, Some(VariableType::ScoreboardValue) => expected == ValueType::Integer,
Some(VariableType::Tag) => expected == ValueType::String, Some(VariableType::Tag) => expected == ValueType::String,
Some(VariableType::ComptimeValue) => true,
_ => false, _ => false,
}, },
Self::Prefix(prefixed) => match prefixed.operator() { Self::Prefix(prefixed) => match prefixed.operator() {

View File

@ -1154,12 +1154,25 @@ impl Parser<'_> {
_ => unreachable!(), _ => unreachable!(),
} }
} }
None => Ok(VariableDeclaration::Single(SingleVariableDeclaration { None => {
variable_type, if matches!(variable_type.keyword, KeywordKind::Val) {
identifier, Ok(VariableDeclaration::ComptimeValue(
assignment, ComptimeValueDeclaration {
annotations: VecDeque::new(), val_keyword: variable_type,
})), identifier,
assignment,
annotations: VecDeque::new(),
},
))
} else {
Ok(VariableDeclaration::Single(SingleVariableDeclaration {
variable_type,
identifier,
assignment,
annotations: VecDeque::new(),
}))
}
}
} }
} }
} }