From e0c3253ab6d7dd5591d37efbb095458135bf3f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Wed, 13 Aug 2025 18:24:48 +0200 Subject: [PATCH] fix comptime variable errors --- src/semantic/mod.rs | 3 ++- src/syntax/syntax_tree/statement.rs | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/semantic/mod.rs b/src/semantic/mod.rs index ab35ef8..015af4d 100644 --- a/src/semantic/mod.rs +++ b/src/semantic/mod.rs @@ -706,13 +706,14 @@ impl Primary { _ => false, }, Self::MemberAccess(_) => { - // TODO: + // TODO: correct return value after check true } Self::Identifier(ident) => match scope.get_variable(ident.span.str()) { Some(VariableType::BooleanStorage) => expected == ValueType::Boolean, Some(VariableType::ScoreboardValue) => expected == ValueType::Integer, Some(VariableType::Tag) => expected == ValueType::String, + Some(VariableType::ComptimeValue) => true, _ => false, }, Self::Prefix(prefixed) => match prefixed.operator() { diff --git a/src/syntax/syntax_tree/statement.rs b/src/syntax/syntax_tree/statement.rs index ad0c0e4..c16ea1e 100644 --- a/src/syntax/syntax_tree/statement.rs +++ b/src/syntax/syntax_tree/statement.rs @@ -1154,12 +1154,25 @@ impl Parser<'_> { _ => unreachable!(), } } - None => Ok(VariableDeclaration::Single(SingleVariableDeclaration { - variable_type, - identifier, - assignment, - annotations: VecDeque::new(), - })), + None => { + if matches!(variable_type.keyword, KeywordKind::Val) { + Ok(VariableDeclaration::ComptimeValue( + ComptimeValueDeclaration { + val_keyword: variable_type, + identifier, + assignment, + annotations: VecDeque::new(), + }, + )) + } else { + Ok(VariableDeclaration::Single(SingleVariableDeclaration { + variable_type, + identifier, + assignment, + annotations: VecDeque::new(), + })) + } + } } } }