Skip to content

Commit

Permalink
feat: enhance config attr type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Peefy committed Sep 12, 2023
1 parent 40d1dcc commit f10be0f
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kclvm/sema/src/resolver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,13 @@ impl<'ctx> Resolver<'ctx> {
doc: None,
},
);
attrs.insert(
string_lit.value.clone(),
Attr {
ty: val_ty.clone(),
range: key.get_span_pos(),
},
);
}
key_types.push(key_ty);
val_types.push(val_ty.clone());
Expand Down
14 changes: 14 additions & 0 deletions test/grammar/types/config/config_ty_0/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
config: {str:} = {
"key" = [
{
key = "value"
}
]
"values": [
"foo"
"bar"
]
}

if "foo" in config.values:
a = 1
7 changes: 7 additions & 0 deletions test/grammar/types/config/config_ty_0/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config:
key:
- key: value
values:
- foo
- bar
a: 1
14 changes: 14 additions & 0 deletions test/grammar/types/config/config_ty_1/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
config: {str:} = {
key = [
{
key = "value"
}
]
values: [
"foo"
"bar"
]
}

if "foo" in config.values:
a = 1
7 changes: 7 additions & 0 deletions test/grammar/types/config/config_ty_1/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config:
key:
- key: value
values:
- foo
- bar
a: 1
12 changes: 12 additions & 0 deletions test/grammar/types/config/config_ty_2/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
config: {str:} = {
"key" = [
{
key = "value"
}
]
"values" = [
"foo"
"bar"
]
}
values: [str] = config.values
9 changes: 9 additions & 0 deletions test/grammar/types/config/config_ty_2/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
config:
key:
- key: value
values:
- foo
- bar
values:
- foo
- bar
12 changes: 12 additions & 0 deletions test/grammar/types/config/config_ty_3/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
config: {str:} = {
"map" = [
{
key = "value"
}
]
"values" = [
"foo"
"bar"
]
}
$map: [{str:str}] = config.map
8 changes: 8 additions & 0 deletions test/grammar/types/config/config_ty_3/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config:
map:
- key: value
values:
- foo
- bar
map:
- key: value

0 comments on commit f10be0f

Please sign in to comment.