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

bugfix: fix schema attr position in sema type #674

Merged
merged 1 commit into from
Aug 21, 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
4 changes: 2 additions & 2 deletions kclvm/sema/src/resolver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl<'ctx> Resolver<'ctx> {
Some(attr_ty_obj) => Some(self.new_config_expr_context_item(
key_name,
attr_ty_obj.ty.clone(),
attr_ty_obj.pos.clone(),
attr_ty_obj.pos.clone(),
attr_ty_obj.range.0.clone(),
attr_ty_obj.range.1.clone(),
)),
None => match &schema_ty.index_signature {
Some(index_signature) => {
Expand Down
25 changes: 17 additions & 8 deletions kclvm/sema/src/resolver/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,25 +578,26 @@ impl<'ctx> Resolver<'ctx> {
};
// Schema attributes
let mut attr_obj_map: IndexMap<String, SchemaAttr> = IndexMap::default();
let settings_dummy_pos = Position {
filename: self.ctx.filename.clone(),
line: pos.line,
column: pos.column,
};
attr_obj_map.insert(
kclvm_runtime::SCHEMA_SETTINGS_ATTR_NAME.to_string(),
SchemaAttr {
is_optional: true,
has_default: false,
default: None,
ty: Type::dict_ref(self.str_ty(), self.any_ty()),
pos: Position {
filename: self.ctx.filename.clone(),
line: pos.line,
column: pos.column,
},
range: (settings_dummy_pos.clone(), settings_dummy_pos),
doc: None,
decorators: vec![],
},
);
let parsed_doc = parse_doc_string(&schema_stmt.doc);
for stmt in &schema_stmt.body {
let (name, ty, is_optional, default, decorators) = match &stmt.node {
let (name, ty, is_optional, default, decorators, range) = match &stmt.node {
ast::Stmt::Unification(unification_stmt) => {
let name = unification_stmt.value.node.name.node.get_name();
let ty = self.parse_ty_str_with_scope(&name, stmt.get_span_pos());
Expand All @@ -608,6 +609,7 @@ impl<'ctx> Resolver<'ctx> {
is_optional,
Some(default),
vec![],
stmt.get_span_pos(),
)
}
ast::Stmt::SchemaAttr(schema_attr) => {
Expand All @@ -627,7 +629,14 @@ impl<'ctx> Resolver<'ctx> {
DecoratorTarget::Attribute,
&name,
);
(name, ty, is_optional, default, decorators)
(
name,
ty,
is_optional,
default,
decorators,
stmt.get_span_pos(),
)
}
_ => continue,
};
Expand All @@ -651,7 +660,7 @@ impl<'ctx> Resolver<'ctx> {
has_default: default.is_some(),
default,
ty: ty.clone(),
pos: pos.clone(),
range: range.clone(),
doc: doc_str,
decorators,
},
Expand Down
5 changes: 3 additions & 2 deletions kclvm/sema/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use context::{TypeContext, TypeInferMethods};
use indexmap::IndexMap;
use kclvm_ast::ast;
use kclvm_ast::MAIN_PKG;
use kclvm_error::diagnostic::Range;
use kclvm_error::Position;
pub use unify::*;
pub use walker::walk_type;
Expand Down Expand Up @@ -218,7 +219,7 @@ impl SchemaType {
has_default: false,
default: None,
ty,
pos: Position::dummy_pos(),
range: (Position::dummy_pos(), Position::dummy_pos()),
doc: None,
decorators: vec![],
};
Expand Down Expand Up @@ -269,7 +270,7 @@ pub struct SchemaAttr {
/// is [None].
pub default: Option<String>,
pub ty: Rc<Type>,
pub pos: Position,
pub range: Range,
pub doc: Option<String>,
pub decorators: Vec<Decorator>,
}
Expand Down
Loading