diff --git a/kclvm/sema/src/resolver/config.rs b/kclvm/sema/src/resolver/config.rs index d9c22962d..f8dbfc96a 100644 --- a/kclvm/sema/src/resolver/config.rs +++ b/kclvm/sema/src/resolver/config.rs @@ -4,7 +4,7 @@ use super::{ scope::{ScopeKind, ScopeObject, ScopeObjectKind}, Resolver, }; -use crate::ty::{sup, DictType, TypeRef}; +use crate::ty::{sup, DictType, TypeInferMethods, TypeRef}; use crate::ty::{Attr, SchemaType}; use crate::ty::{Type, TypeKind}; use indexmap::IndexMap; @@ -431,7 +431,7 @@ impl<'ctx> Resolver<'ctx> { attrs.insert( name.to_string(), Attr { - ty: ty.clone(), + ty: self.ctx.ty_ctx.infer_to_variable_type(ty.clone()), range: key.get_span_pos(), }, ); @@ -476,7 +476,7 @@ impl<'ctx> Resolver<'ctx> { attrs.insert( string_lit.value.clone(), Attr { - ty: ty.clone(), + ty: self.ctx.ty_ctx.infer_to_variable_type(ty.clone()), range: key.get_span_pos(), }, ); diff --git a/kclvm/sema/src/ty/context.rs b/kclvm/sema/src/ty/context.rs index 7bbe04030..66ad71c01 100644 --- a/kclvm/sema/src/ty/context.rs +++ b/kclvm/sema/src/ty/context.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::sync::Arc; -use super::{sup, Attr, DictType, Type, TypeFlags, TypeKind, TypeRef}; +use super::{sup, DictType, Type, TypeFlags, TypeKind, TypeRef}; use petgraph::algo::is_cyclic_directed; use petgraph::graph::{DiGraph, NodeIndex}; @@ -173,18 +173,7 @@ impl TypeInferMethods for TypeContext { }) => Type::dict_ref_with_attrs( self.infer_to_variable_type(key_ty.clone()), self.infer_to_variable_type(val_ty.clone()), - attrs - .into_iter() - .map(|(key, attr)| { - ( - key.to_string(), - Attr { - ty: self.infer_to_variable_type(attr.ty.clone()), - range: attr.range.clone(), - }, - ) - }) - .collect(), + attrs.clone(), ), // Union type e.g., 1|2|"s" -> int|str TypeKind::Union(types) => sup(&types