Skip to content

Commit e98adff

Browse files
authored
KCL: Relax double-close error to warning (#7943)
Closing an already-closed sketch is now a warning, not an error. Unfortunately this is tricky to add an autofix suggestion for, because our current suggestion ("delete the close call") would turn `|> close()` into `|>` with our current autofix implementation
1 parent d2634bf commit e98adff

File tree

5 files changed

+161
-30
lines changed

5 files changed

+161
-30
lines changed

rust/kcl-lib/src/std/sketch.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,10 +1233,14 @@ pub(crate) async fn inner_close(
12331233
args: Args,
12341234
) -> Result<Sketch, KclError> {
12351235
if sketch.is_closed {
1236-
return Err(KclError::new_semantic(KclErrorDetails::new(
1237-
"This sketch is already closed. Remove this unnecessary `close()` call".to_owned(),
1238-
vec![args.source_range],
1239-
)));
1236+
exec_state.warn(crate::CompilationError {
1237+
source_range: args.source_range,
1238+
message: "This sketch is already closed. Remove this unnecessary `close()` call".to_string(),
1239+
suggestion: None,
1240+
severity: crate::errors::Severity::Warning,
1241+
tag: crate::errors::Tag::Unnecessary,
1242+
});
1243+
return Ok(sketch);
12401244
}
12411245
let from = sketch.current_pen_position()?;
12421246
let to = point_to_len_unit(sketch.start.get_from(), from.units);

rust/kcl-lib/tests/double_close/execution_error.snap

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: kcl-lib/src/simulation_tests.rs
3+
description: Execution success double_close.kcl
4+
---
5+
null

rust/kcl-lib/tests/double_close/program_memory.snap

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,151 @@
22
source: kcl-lib/src/simulation_tests.rs
33
description: Variables in memory after executing double_close.kcl
44
---
5-
{}
5+
{
6+
"shape": {
7+
"type": "Sketch",
8+
"value": {
9+
"type": "Sketch",
10+
"id": "[uuid]",
11+
"paths": [
12+
{
13+
"__geoMeta": {
14+
"id": "[uuid]",
15+
"sourceRange": []
16+
},
17+
"from": [
18+
-5.0,
19+
-5.0
20+
],
21+
"tag": null,
22+
"to": [
23+
5.0,
24+
-5.0
25+
],
26+
"type": "ToPoint",
27+
"units": {
28+
"type": "Mm"
29+
}
30+
},
31+
{
32+
"__geoMeta": {
33+
"id": "[uuid]",
34+
"sourceRange": []
35+
},
36+
"from": [
37+
5.0,
38+
-5.0
39+
],
40+
"tag": null,
41+
"to": [
42+
5.0,
43+
5.0
44+
],
45+
"type": "ToPoint",
46+
"units": {
47+
"type": "Mm"
48+
}
49+
},
50+
{
51+
"__geoMeta": {
52+
"id": "[uuid]",
53+
"sourceRange": []
54+
},
55+
"from": [
56+
5.0,
57+
5.0
58+
],
59+
"tag": null,
60+
"to": [
61+
-5.0,
62+
5.0
63+
],
64+
"type": "ToPoint",
65+
"units": {
66+
"type": "Mm"
67+
}
68+
},
69+
{
70+
"__geoMeta": {
71+
"id": "[uuid]",
72+
"sourceRange": []
73+
},
74+
"from": [
75+
-5.0,
76+
5.0
77+
],
78+
"tag": null,
79+
"to": [
80+
-5.0,
81+
-5.0
82+
],
83+
"type": "ToPoint",
84+
"units": {
85+
"type": "Mm"
86+
}
87+
}
88+
],
89+
"on": {
90+
"artifactId": "[uuid]",
91+
"id": "[uuid]",
92+
"origin": {
93+
"x": 0.0,
94+
"y": 0.0,
95+
"z": 0.0,
96+
"units": {
97+
"type": "Mm"
98+
}
99+
},
100+
"type": "plane",
101+
"value": "XY",
102+
"xAxis": {
103+
"x": 1.0,
104+
"y": 0.0,
105+
"z": 0.0,
106+
"units": {
107+
"type": "Unknown"
108+
}
109+
},
110+
"yAxis": {
111+
"x": 0.0,
112+
"y": 1.0,
113+
"z": 0.0,
114+
"units": {
115+
"type": "Unknown"
116+
}
117+
},
118+
"zAxis": {
119+
"x": 0.0,
120+
"y": 0.0,
121+
"z": 1.0,
122+
"units": {
123+
"type": "Unknown"
124+
}
125+
}
126+
},
127+
"start": {
128+
"from": [
129+
-5.0,
130+
-5.0
131+
],
132+
"to": [
133+
-5.0,
134+
-5.0
135+
],
136+
"units": {
137+
"type": "Mm"
138+
},
139+
"tag": null,
140+
"__geoMeta": {
141+
"id": "[uuid]",
142+
"sourceRange": []
143+
}
144+
},
145+
"artifactId": "[uuid]",
146+
"originalId": "[uuid]",
147+
"units": {
148+
"type": "Mm"
149+
}
150+
}
151+
}
152+
}
26.8 KB
Loading

0 commit comments

Comments
 (0)