Skip to content

Commit

Permalink
fix empty dict
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa committed May 30, 2024
1 parent a17ccd5 commit 19070b5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions kclvm/sema/src/resolver/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ impl<'ctx> Resolver<'ctx> {
range: &Range,
) -> TypeRef {
match (&ty.kind, &expected_ty.kind) {
(TypeKind::Dict(DictType { key_ty, val_ty, .. }), TypeKind::Schema(schema_ty)) => {
if self.dict_assignable_to_schema(key_ty.clone(), val_ty.clone(), schema_ty, range)
{
(TypeKind::Dict(DictType { key_ty, .. }), TypeKind::Schema(schema_ty)) => {
if self.upgrade_dict_to_schema_attr_check(key_ty.clone(), schema_ty) {
expected_ty
} else {
ty
Expand Down Expand Up @@ -333,7 +332,15 @@ impl<'ctx> Resolver<'ctx> {
return true;
}
match &key_ty.kind {
// empty dict {}
TypeKind::Any => true,
// single key: {key1: value1}
TypeKind::StrLit(s) => schema_ty.attrs.len() == 1 && schema_ty.attrs.contains_key(s),
// multi key: {
// key1: value1
// key2: value2
// ...
// }
TypeKind::Union(types) => {
schema_ty.attrs.len() == types.len()
&& types.iter().all(|ty| match &ty.kind {
Expand Down

0 comments on commit 19070b5

Please sign in to comment.