Skip to content

Commit

Permalink
use full_ty_str() to calculate schame name in cycle
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa committed Sep 14, 2024
1 parent 9262d40 commit 9a4a897
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
21 changes: 7 additions & 14 deletions kclvm/sema/src/resolver/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use std::sync::Arc;
use crate::info::is_private_field;
use crate::resolver::Resolver;
use crate::ty::{
is_upper_bound, DecoratorTarget, FunctionType, Parameter, SchemaAttr, SchemaIndexSignature,
SchemaType, Type, TypeKind, RESERVED_TYPE_IDENTIFIERS,
full_ty_str, is_upper_bound, DecoratorTarget, FunctionType, Parameter, SchemaAttr,
SchemaIndexSignature, SchemaType, Type, TypeKind, RESERVED_TYPE_IDENTIFIERS,
};
use indexmap::IndexMap;
use kclvm_ast::{ast, MAIN_PKG};
use kclvm_ast::ast;
use kclvm_ast_pretty::{print_ast_node, print_schema_expr, ASTNode};
use kclvm_error::*;

Expand Down Expand Up @@ -757,11 +757,8 @@ impl<'ctx> Resolver<'ctx> {
}
}

let schema_full_ty_str = if self.ctx.pkgpath == MAIN_PKG || self.ctx.pkgpath.is_empty() {
name.to_string()
} else {
kclvm_runtime::schema_runtime_type(name, &self.ctx.pkgpath)
};
let schema_full_ty_str = full_ty_str(&self.ctx.pkgpath, name);

if should_add_schema_ref {
if let Some(ref parent_ty) = parent_ty {
let parent_full_ty_str = parent_ty.full_ty_str();
Expand Down Expand Up @@ -895,12 +892,8 @@ impl<'ctx> Resolver<'ctx> {
}
}
if should_add_schema_ref {
let schema_full_ty_str = if self.ctx.pkgpath == MAIN_PKG || self.ctx.pkgpath.is_empty()
{
name.to_string()
} else {
kclvm_runtime::schema_runtime_type(name, &self.ctx.pkgpath)
};
let schema_full_ty_str = full_ty_str(&self.ctx.pkgpath, &name);

for parent_ty in &parent_types {
let parent_full_ty_str = parent_ty.full_ty_str();
self.ctx.ty_ctx.add_dependencies(
Expand Down
14 changes: 9 additions & 5 deletions kclvm/sema/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,7 @@ impl SchemaType {
}
/// Get the object type string.
pub fn full_ty_str(&self) -> String {
if self.pkgpath.is_empty() || self.pkgpath == MAIN_PKG {
self.name.clone()
} else {
format!("{}.{}", self.pkgpath, self.name)
}
full_ty_str(&self.pkgpath, &self.name)
}
/// Is `name` a schema member function
pub fn is_member_functions(&self, name: &str) -> bool {
Expand Down Expand Up @@ -375,6 +371,14 @@ impl SchemaType {
}
}

pub fn full_ty_str(pkgpath: &str, name: &str) -> String {
if pkgpath.is_empty() || pkgpath == MAIN_PKG {
name.to_string()
} else {
format!("{}.{}", pkgpath, name)
}
}

#[derive(Debug, Clone, PartialEq)]
pub struct SchemaAttr {
pub is_optional: bool,
Expand Down

0 comments on commit 9a4a897

Please sign in to comment.