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

refactor: joined string and missing key recovery for better error messages. #551

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions kclvm/sema/src/resolver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ impl<'ctx> Resolver<'ctx> {
}
}
ast::Expr::StringLit(string_lit) => vec![string_lit.value.clone()],
// There may be a valid configuration key for joined string and missing expressions here,
// and we will restore it to a null value to avoid unfriendly error messages.
ast::Expr::JoinedString(_) | ast::Expr::Missing(_) => vec!["".to_string()],
_ => return SwitchConfigContextState::KeepConfigUnchanged as usize,
};
self.switch_config_expr_context_by_names(&names)
Expand All @@ -159,7 +162,7 @@ impl<'ctx> Resolver<'ctx> {
///
/// Returns:
/// push stack times
pub(crate) fn switch_config_exprr_context_by_name(&mut self, name: &str) -> usize {
pub(crate) fn switch_config_expr_context_by_name(&mut self, name: &str) -> usize {
let ctx_obj = self.find_schema_attr_obj_from_schema_expr_stack(name);
self.switch_config_expr_context(ctx_obj) as usize
}
Expand Down Expand Up @@ -220,7 +223,7 @@ impl<'ctx> Resolver<'ctx> {
pub(crate) fn switch_config_expr_context_by_names(&mut self, names: &[String]) -> usize {
let mut stack_depth = 0;
for name in names {
stack_depth += self.switch_config_exprr_context_by_name(name);
stack_depth += self.switch_config_expr_context_by_name(name);
}
stack_depth
}
Expand Down Expand Up @@ -287,7 +290,7 @@ impl<'ctx> Resolver<'ctx> {
let mut stack_depth = 0;
for name in &names {
self.check_config_expr_by_key_name(name, key);
stack_depth += self.switch_config_exprr_context_by_name(name);
stack_depth += self.switch_config_expr_context_by_name(name);
}
let mut val_ty = self.expr(value);
for _ in 0..names.len() - 1 {
Expand Down
13 changes: 13 additions & 0 deletions test/grammar/types/interpolation/interpolation_0/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
schema App:
name: str
containers?: {str: Container}

schema Container:
image: str

app: App {
name = "ngnix"
containers = {
"${name}" = {image = name}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
app:
name: ngnix
containers:
ngnix:
image: ngnix
23 changes: 23 additions & 0 deletions test/grammar/types/interpolation/interpolation_1/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
schema App:
name: str
containers?: {str: Container}

schema Container:
image: str
envs: {str:Env}

schema Env:
value?: str
valueFrom?: str

app: App {
name = "ngnix"
containers = {
"${name}" = {
image = name
envs = {
"${name}" = {value = "value"}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
app:
name: ngnix
containers:
ngnix:
image: ngnix
envs:
ngnix:
value: value