BREAKING: Change to disallow indexing KCL records/objects with strings (#6529)

* Change to disallow indexing records/objects with strings

* Update output

* Remove outdated sim test

* Fix tests
This commit is contained in:
Jonathan Tran
2025-04-28 12:08:47 -04:00
committed by GitHub
parent 719136937e
commit 2e754f2a11
26 changed files with 297 additions and 1633 deletions

View File

@ -0,0 +1,32 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Artifact commands invalid_member_object_using_string.kcl
---
[
{
"cmdId": "[uuid]",
"range": [],
"command": {
"type": "edge_lines_visible",
"hidden": false
}
},
{
"cmdId": "[uuid]",
"range": [],
"command": {
"type": "object_visible",
"object_id": "[uuid]",
"hidden": true
}
},
{
"cmdId": "[uuid]",
"range": [],
"command": {
"type": "object_visible",
"object_id": "[uuid]",
"hidden": true
}
}
]

View File

@ -0,0 +1,6 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Artifact graph flowchart invalid_member_object_using_string.kcl
extension: md
snapshot_kind: binary
---

View File

@ -0,0 +1,3 @@
```mermaid
flowchart LR
```

View File

@ -0,0 +1,196 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Result of parsing invalid_member_object_using_string.kcl
---
{
"Ok": {
"body": [
{
"commentStart": 0,
"declaration": {
"commentStart": 0,
"end": 0,
"id": {
"commentStart": 0,
"end": 0,
"name": "p",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 0,
"end": 0,
"raw": "\"foo\"",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": "foo"
},
"start": 0,
"type": "VariableDeclarator"
},
"end": 0,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 0,
"declaration": {
"commentStart": 0,
"end": 0,
"id": {
"commentStart": 0,
"end": 0,
"name": "obj",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 0,
"end": 0,
"properties": [
{
"commentStart": 0,
"end": 0,
"key": {
"commentStart": 0,
"end": 0,
"name": "foo",
"start": 0,
"type": "Identifier"
},
"start": 0,
"type": "ObjectProperty",
"value": {
"commentStart": 0,
"end": 0,
"raw": "1",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 1.0,
"suffix": "None"
}
}
},
{
"commentStart": 0,
"end": 0,
"key": {
"commentStart": 0,
"end": 0,
"name": "bar",
"start": 0,
"type": "Identifier"
},
"start": 0,
"type": "ObjectProperty",
"value": {
"commentStart": 0,
"end": 0,
"raw": "0",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 0.0,
"suffix": "None"
}
}
}
],
"start": 0,
"type": "ObjectExpression",
"type": "ObjectExpression"
},
"start": 0,
"type": "VariableDeclarator"
},
"end": 0,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 0,
"declaration": {
"commentStart": 0,
"end": 0,
"id": {
"commentStart": 0,
"end": 0,
"name": "one",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 0,
"computed": true,
"end": 0,
"object": {
"commentStart": 0,
"end": 0,
"name": "obj",
"start": 0,
"type": "Identifier",
"type": "Identifier"
},
"property": {
"commentStart": 0,
"end": 0,
"name": "p",
"start": 0,
"type": "Identifier",
"type": "Identifier"
},
"start": 0,
"type": "MemberExpression",
"type": "MemberExpression"
},
"start": 0,
"type": "VariableDeclarator"
},
"end": 0,
"kind": "const",
"preComments": [
"// Try to index with a string."
],
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
}
],
"commentStart": 0,
"end": 0,
"nonCodeMeta": {
"nonCodeNodes": {},
"startNodes": [
{
"commentStart": 0,
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
"value": "This tests computed properties.",
"style": "line"
}
},
{
"commentStart": 0,
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"start": 0
}
}

View File

@ -0,0 +1,14 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Error from executing invalid_member_object_using_string.kcl
---
KCL Semantic error
× semantic: Cannot index object with string; use dot notation instead, e.g.
│ `obj.foo`
╭─[6:7]
5 │ // Try to index with a string.
6 │ one = obj[p]
· ───┬──
· ╰── tests/invalid_member_object_using_string/input.kcl
╰────

View File

@ -0,0 +1,6 @@
// This tests computed properties.
p = "foo"
obj = { foo = 1, bar = 0 }
// Try to index with a string.
one = obj[p]

View File

@ -0,0 +1,5 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Operations executed invalid_member_object_using_string.kcl
---
[]

View File

@ -0,0 +1,11 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Result of unparsing invalid_member_object_using_string.kcl
---
// This tests computed properties.
p = "foo"
obj = { foo = 1, bar = 0 }
// Try to index with a string.
one = obj[p]