diff --git a/kclvm/sema/src/resolver/config.rs b/kclvm/sema/src/resolver/config.rs index d3960ec50..14a99f94c 100644 --- a/kclvm/sema/src/resolver/config.rs +++ b/kclvm/sema/src/resolver/config.rs @@ -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()); diff --git a/test/grammar/types/config/config_ty_0/main.k b/test/grammar/types/config/config_ty_0/main.k new file mode 100644 index 000000000..377e25e8d --- /dev/null +++ b/test/grammar/types/config/config_ty_0/main.k @@ -0,0 +1,14 @@ +config: {str:} = { + "key" = [ + { + key = "value" + } + ] + "values": [ + "foo" + "bar" + ] +} + +if "foo" in config.values: + a = 1 diff --git a/test/grammar/types/config/config_ty_0/stdout.golden b/test/grammar/types/config/config_ty_0/stdout.golden new file mode 100644 index 000000000..5868ff014 --- /dev/null +++ b/test/grammar/types/config/config_ty_0/stdout.golden @@ -0,0 +1,7 @@ +config: + key: + - key: value + values: + - foo + - bar +a: 1 diff --git a/test/grammar/types/config/config_ty_1/main.k b/test/grammar/types/config/config_ty_1/main.k new file mode 100644 index 000000000..ea3920300 --- /dev/null +++ b/test/grammar/types/config/config_ty_1/main.k @@ -0,0 +1,14 @@ +config: {str:} = { + key = [ + { + key = "value" + } + ] + values: [ + "foo" + "bar" + ] +} + +if "foo" in config.values: + a = 1 diff --git a/test/grammar/types/config/config_ty_1/stdout.golden b/test/grammar/types/config/config_ty_1/stdout.golden new file mode 100644 index 000000000..5868ff014 --- /dev/null +++ b/test/grammar/types/config/config_ty_1/stdout.golden @@ -0,0 +1,7 @@ +config: + key: + - key: value + values: + - foo + - bar +a: 1 diff --git a/test/grammar/types/config/config_ty_2/main.k b/test/grammar/types/config/config_ty_2/main.k new file mode 100644 index 000000000..f93e476a1 --- /dev/null +++ b/test/grammar/types/config/config_ty_2/main.k @@ -0,0 +1,12 @@ +config: {str:} = { + "key" = [ + { + key = "value" + } + ] + "values" = [ + "foo" + "bar" + ] +} +values: [str] = config.values diff --git a/test/grammar/types/config/config_ty_2/stdout.golden b/test/grammar/types/config/config_ty_2/stdout.golden new file mode 100644 index 000000000..e5349a781 --- /dev/null +++ b/test/grammar/types/config/config_ty_2/stdout.golden @@ -0,0 +1,9 @@ +config: + key: + - key: value + values: + - foo + - bar +values: +- foo +- bar diff --git a/test/grammar/types/config/config_ty_3/main.k b/test/grammar/types/config/config_ty_3/main.k new file mode 100644 index 000000000..7e1a11194 --- /dev/null +++ b/test/grammar/types/config/config_ty_3/main.k @@ -0,0 +1,12 @@ +config: {str:} = { + "map" = [ + { + key = "value" + } + ] + "values" = [ + "foo" + "bar" + ] +} +$map: [{str:str}] = config.map diff --git a/test/grammar/types/config/config_ty_3/stdout.golden b/test/grammar/types/config/config_ty_3/stdout.golden new file mode 100644 index 000000000..cf7c1c5e8 --- /dev/null +++ b/test/grammar/types/config/config_ty_3/stdout.golden @@ -0,0 +1,8 @@ +config: + map: + - key: value + values: + - foo + - bar +map: +- key: value