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

Quick fixes for more compile errors #1360

Merged
merged 8 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
26 changes: 16 additions & 10 deletions kclvm/sema/src/resolver/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,24 +471,30 @@ impl<'ctx> Resolver<'ctx> {
) -> SchemaType {
let name = &schema_stmt.name.node;
if RESERVED_TYPE_IDENTIFIERS.contains(&name.as_str()) {
self.handler.add_compile_error(
self.handler.add_compile_error_with_suggestions(
&format!(
"schema name '{}' cannot be the same as the built-in types ({:?})",
name, RESERVED_TYPE_IDENTIFIERS
),
schema_stmt.name.get_span_pos(),
Some(vec![]),
);
}
if schema_stmt.is_protocol && !name.ends_with(PROTOCOL_SUFFIX) {
self.handler.add_error(
ErrorKind::CompileError,
&[Message {
range: schema_stmt.name.get_span_pos(),
style: Style::LineAndColumn,
message: format!("schema protocol name must end with '{}'", PROTOCOL_SUFFIX),
note: None,
suggested_replacement: None,
}],
let fix_range = schema_stmt.name.get_span_pos();
let (start_pos, end_pos) = fix_range;
let start_column = end_pos.column;

let modified_start_pos = Position {
column: start_column,
..start_pos.clone()
};
let modified_fix_range = (modified_start_pos, end_pos);

self.handler.add_compile_error_with_suggestions(
&format!("schema protocol name must end with '{}'", PROTOCOL_SUFFIX),
modified_fix_range,
Some(vec![PROTOCOL_SUFFIX.to_string()]),
);
}
if schema_stmt.is_protocol && !schema_stmt.has_only_attribute_definitions() {
Expand Down
33 changes: 29 additions & 4 deletions kclvm/sema/src/resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,28 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
let mut value_ty = self.expr(&selector_expr.value);
if value_ty.is_module() && selector_expr.has_question {
let attr = selector_expr.attr.node.get_name();
self.handler.add_compile_error(
let fix_range = selector_expr.value.get_span_pos();
let (start_pos, end_pos) = fix_range;
let start_column = end_pos.column;
let end_column = end_pos.column.map(|col| col.saturating_add(1));
let modified_start_pos = Position {
column: start_column,
..start_pos.clone()
};
let modified_end_pos = Position {
column: end_column,
..end_pos.clone()
};
let modified_fix_range = (modified_start_pos, modified_end_pos);

self.handler.add_compile_error_with_suggestions(
&format!(
"For the module type, the use of '?.{}' is unnecessary and it can be modified as '.{}'",
attr,
attr
),
selector_expr.value.get_span_pos(),
modified_fix_range,
Some(vec![])
);
}
for name in &selector_expr.attr.node.names {
Expand Down Expand Up @@ -889,12 +904,22 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
} else if i == 1 {
val_name = Some(name);
} else {
self.handler.add_compile_error(
let fix_range = target.get_span_pos();
let (start_pos, end_pos) = fix_range;
let start_column = start_pos.column.map(|col| col.saturating_sub(2));

let modified_start_pos = Position {
column: start_column,
..start_pos.clone()
};
let modified_fix_range = (modified_start_pos, end_pos);
self.handler.add_compile_error_with_suggestions(
&format!(
"the number of loop variables is {}, which can only be 1 or 2",
comp_clause.targets.len()
),
target.get_span_pos(),
modified_fix_range,
Some(vec![]),
);
break;
}
Expand Down
3 changes: 2 additions & 1 deletion kclvm/sema/src/resolver/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@ impl<'ctx> Resolver<'ctx> {
_ => bug!("invalid builtin decorator function type"),
},
None => {
self.handler.add_compile_error(
self.handler.add_compile_error_with_suggestions(
&format!("UnKnown decorator {}", name),
decorator.get_span_pos(),
Some(vec![]),
);
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
error[E2L23]: CompileError
--> ${CWD}/main.k:2:25
--> ${CWD}/main.k:2:23
|
2 | dataLoop = [i for i, j, k in data] # error
| ^ the number of loop variables is 3, which can only be 1 or 2
| ^ the number of loop variables is 3, which can only be 1 or 2
Peefy marked this conversation as resolved.
Show resolved Hide resolved
|
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
error[E2L23]: CompileError
--> ${CWD}/main.k:2:25
--> ${CWD}/main.k:2:23
|
2 | dataLoop = [i for i, j, k in data] # error
| ^ the number of loop variables is 3, which can only be 1 or 2
| ^ the number of loop variables is 3, which can only be 1 or 2
|
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
error[E2L23]: CompileError
--> ${CWD}/main.k:2:25
--> ${CWD}/main.k:2:23
|
2 | dataLoop = [i for i, j, k in dataString] # error
| ^ the number of loop variables is 3, which can only be 1 or 2
| ^ the number of loop variables is 3, which can only be 1 or 2
|
Loading