Skip to content

Commit 64b7c34

Browse files
committed
More warnings
Signed-off-by: Nick Cameron <nrc@ncameron.org>
1 parent 20c074d commit 64b7c34

File tree

13 files changed

+149
-124
lines changed

13 files changed

+149
-124
lines changed

e2e/playwright/editor-tests.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ a1 = startSketchOn(offsetPlane(XY, offset = 10))
912912
|> close()
913913
|> revolve(
914914
axis = revolveAxis,
915-
angle = 90
915+
angle = 90deg
916916
)
917917
`
918918
)

e2e/playwright/point-click.spec.ts

Lines changed: 68 additions & 68 deletions
Large diffs are not rendered by default.

e2e/playwright/snapshot-tests.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -845,14 +845,14 @@ test.describe('code color goober', { tag: '@snapshot' }, () => {
845845
sweepPath = startSketchOn(XZ)
846846
|> startProfile(at = [0.05, 0.05])
847847
|> line(end = [0, 7])
848-
|> tangentialArc(angle = 90, radius = 5)
848+
|> tangentialArc(angle = 90deg, radius = 5)
849849
|> line(end = [-3, 0])
850-
|> tangentialArc(angle = -90, radius = 5)
850+
|> tangentialArc(angle = -90deg, radius = 5)
851851
|> line(end = [0, 7])
852852
853853
sweepSketch = startSketchOn(XY)
854854
|> startProfile(at = [2, 0])
855-
|> arc(angleStart = 0, angleEnd = 360, radius = 2)
855+
|> arc(angleStart = 0, angleEnd = 360deg, radius = 2)
856856
|> sweep(path = sweepPath)
857857
|> appearance(
858858
color = "#bb00ff",
@@ -889,14 +889,14 @@ sweepSketch = startSketchOn(XY)
889889
sweepPath = startSketchOn(XZ)
890890
|> startProfile(at = [0.05, 0.05])
891891
|> line(end = [0, 7])
892-
|> tangentialArc(angle = 90, radius = 5)
892+
|> tangentialArc(angle = 90deg, radius = 5)
893893
|> line(end = [-3, 0])
894-
|> tangentialArc(angle = -90, radius = 5)
894+
|> tangentialArc(angle = -90deg, radius = 5)
895895
|> line(end = [0, 7])
896896
897897
sweepSketch = startSketchOn(XY)
898898
|> startProfile(at = [2, 0])
899-
|> arc(angleStart = 0, angleEnd = 360, radius = 2)
899+
|> arc(angleStart = 0deg, angleEnd = 360deg, radius = 2)
900900
|> sweep(path = sweepPath)
901901
|> appearance(
902902
color = '#bb00ff',
@@ -934,14 +934,14 @@ sweepSketch = startSketchOn(XY)
934934
sweepPath = startSketchOn(XZ)
935935
|> startProfile(at = [0.05, 0.05])
936936
|> line(end = [0, 7])
937-
|> tangentialArc(angle = 90, radius = 5)
937+
|> tangentialArc(angle = 90deg, radius = 5)
938938
|> line(end = [-3, 0])
939-
|> tangentialArc(angle = -90, radius = 5)
939+
|> tangentialArc(angle = -90deg, radius = 5)
940940
|> line(end = [0, 7])
941941
942942
sweepSketch = startSketchOn(XY)
943943
|> startProfile(at = [2, 0])
944-
|> arc(angleStart = 0, angleEnd = 360, radius = 2)
944+
|> arc(angleStart = 0deg, angleEnd = 360deg, radius = 2)
945945
|> sweep(path = sweepPath)
946946
|> appearance(
947947
color = "#bb00ff",

e2e/playwright/testing-constraints.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test.describe('Testing constraints', () => {
5757
.click()
5858

5959
await expect(page.locator('.cm-content')).toHaveText(
60-
`length001 = 20sketch001 = startSketchOn(XY) |> startProfile(at = [-10, -10]) |> line(end = [20, 0]) |> angledLine(angle = 90, length = length001) |> xLine(length = -20)`
60+
`length001 = 20sketch001 = startSketchOn(XY) |> startProfile(at = [-10, -10]) |> line(end = [20, 0]) |> angledLine(angle = 90deg, length = length001) |> xLine(length = -20)`
6161
)
6262

6363
// Make sure we didn't pop out of sketch mode.
@@ -208,7 +208,9 @@ test.describe('Testing constraints', () => {
208208
.click()
209209

210210
// Wait for the codemod to take effect
211-
await expect(page.locator('.cm-content')).toContainText(`angle = -57,`)
211+
await expect(page.locator('.cm-content')).toContainText(
212+
`angle = -57deg,`
213+
)
212214
await expect(page.locator('.cm-content')).toContainText(
213215
`offset = ${offset},`
214216
)
@@ -219,7 +221,7 @@ test.describe('Testing constraints', () => {
219221
`|> line(end = [74.36, 130.4], tag = $seg01)`
220222
)
221223
await expect(activeLinesContent[1]).toHaveText(
222-
` |> angledLineThatIntersects(angle = -57, offset = ${offset}, intersectTag = seg01)`
224+
` |> angledLineThatIntersects(angle = -57deg, offset = ${offset}, intersectTag = seg01)`
223225
)
224226

225227
// checking the count of the overlays is a good proxy check that the client sketch scene is in a good state
@@ -470,7 +472,7 @@ test.describe('Testing constraints', () => {
470472
testName: 'No variable',
471473
addVariable: false,
472474
axisSelect: false,
473-
value: 'segAng(seg01) + 22.69',
475+
value: 'segAng(seg01) + 22.69deg',
474476
},
475477
{
476478
testName: 'Add variable, selecting axis',
@@ -482,7 +484,7 @@ test.describe('Testing constraints', () => {
482484
testName: 'No variable, selecting axis',
483485
addVariable: false,
484486
axisSelect: true,
485-
value: 'turns::QUARTER_TURN - 7',
487+
value: 'turns::QUARTER_TURN - 7deg',
486488
},
487489
] as const
488490
for (const { testName, addVariable, value, axisSelect } of cases) {
@@ -657,13 +659,13 @@ test.describe('Testing constraints', () => {
657659
testName: 'Length - Add variable',
658660
addVariable: true,
659661
constraint: 'length',
660-
value: '83, length001',
662+
value: '83deg, length001',
661663
},
662664
{
663665
testName: 'Length - No variable',
664666
addVariable: false,
665667
constraint: 'length',
666-
value: '83, 78.33',
668+
value: '83deg, 78.33',
667669
},
668670
] as const
669671
for (const { testName, addVariable, value, constraint } of cases) {
@@ -852,7 +854,7 @@ part002 = startSketchOn(XZ)
852854
test.describe('Two segment - no modal constraints', () => {
853855
const cases = [
854856
{
855-
codeAfter: `|> angledLine(angle = 83, length = segLen(seg01))`,
857+
codeAfter: `|> angledLine(angle = 83deg, length = segLen(seg01))`,
856858
constraintName: 'Equal Length',
857859
},
858860
{
@@ -1174,7 +1176,7 @@ test.describe('Electron constraint tests', () => {
11741176
await cmdBar.progressCmdBar()
11751177
await editor.expectEditor.toContain('length001 = 15.3')
11761178
await editor.expectEditor.toContain(
1177-
'|> angledLine(angle = 9, length = length001)'
1179+
'|> angledLine(angle = 9deg, length = length001)'
11781180
)
11791181
})
11801182

rust/kcl-lib/e2e/executor/inputs/e2e-can-sketch-on-chamfer-no-pipeExpr.kcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@settings(defaultLengthUnit = in)
22
sketch001 = startSketchOn(XZ)
33
|> startProfile(at = [75.8, 317.2])
4-
|> angledLine(angle = 0, length = 268.43, tag = $rectangleSegmentA001)
5-
|> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = 217.26, tag = $seg01)
4+
|> angledLine(angle = 0deg, length = 268.43, tag = $rectangleSegmentA001)
5+
|> angledLine(angle = segAng(rectangleSegmentA001) - 90deg, length = 217.26, tag = $seg01)
66
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $yo)
77
|> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $seg02)
88
|> close()

rust/kcl-lib/e2e/executor/inputs/e2e-can-sketch-on-chamfer.kcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@settings(defaultLengthUnit = in)
22
sketch001 = startSketchOn(XZ)
33
|> startProfile(at = [75.8, 317.2]) // [$startCapTag, $EndCapTag]
4-
|> angledLine(angle = 0, length = 268.43, tag = $rectangleSegmentA001)
5-
|> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = 217.26, tag = $seg01)
4+
|> angledLine(angle = 0deg, length = 268.43, tag = $rectangleSegmentA001)
5+
|> angledLine(angle = segAng(rectangleSegmentA001) - 90deg, length = 217.26, tag = $seg01)
66
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $yo)
77
|> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $seg02)
88
|> close()

rust/kcl-lib/src/execution/annotations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
};
1313

1414
/// Annotations which should cause re-execution if they change.
15-
pub(super) const SIGNIFICANT_ATTRS: [&str; 2] = [SETTINGS, NO_PRELUDE];
15+
pub(super) const SIGNIFICANT_ATTRS: [&str; 3] = [SETTINGS, NO_PRELUDE, WARNINGS];
1616

1717
pub(crate) const SETTINGS: &str = "settings";
1818
pub(crate) const SETTINGS_UNIT_LENGTH: &str = "defaultLengthUnit";
@@ -162,7 +162,7 @@ pub(super) fn many_of(
162162
vec![source_range],
163163
))
164164
})
165-
.map(|v| *v)
165+
.copied()
166166
})
167167
.collect::<Result<Vec<&str>, KclError>>()
168168
}

rust/kcl-lib/src/execution/exec_ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,7 @@ impl Node<PipeExpression> {
17801780
#[cfg(test)]
17811781
mod test {
17821782
use std::sync::Arc;
1783+
17831784
use tokio::io::AsyncWriteExt;
17841785

17851786
use super::*;

rust/kcl-lib/src/execution/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,9 @@ impl ExecutorContext {
604604
settings: &self.settings,
605605
};
606606

607+
let cache_result = cache::get_changed_program(old, new).await;
607608
// Get the program that actually changed from the old and new information.
608-
let (clear_scene, program, import_check_info) = match cache::get_changed_program(old, new).await {
609+
let (clear_scene, program, import_check_info) = match cache_result {
609610
CacheResult::ReExecute {
610611
clear_scene,
611612
reapply_settings,

rust/kcl-lib/src/execution/types.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ impl NumericType {
760760
}
761761
}
762762

763-
fn coerce(&self, val: &KclValue) -> Result<KclValue, CoercionError> {
763+
fn coerce(&self, val: &KclValue, exec_state: &mut ExecState) -> Result<KclValue, CoercionError> {
764764
let KclValue::Number { value, ty, meta } = val else {
765765
return Err(val.into());
766766
};
@@ -832,6 +832,14 @@ impl NumericType {
832832
}
833833

834834
(Default { angle: a1, .. }, Known(UnitType::Angle(a2))) => {
835+
let mut source_ranges = Into::<Vec<SourceRange>>::into(val);
836+
// A single source range means it's not via a function or something.
837+
if source_ranges.len() == 1 {
838+
exec_state.warn(
839+
CompilationError::err(source_ranges.pop().unwrap(), "Prefer to use explicit units for angles"),
840+
annotations::WARN_ANGLE_UNITS,
841+
);
842+
}
835843
let (value, ty) = a1.adjust_to(*value, *a2);
836844
Ok(KclValue::Number {
837845
value,
@@ -1156,7 +1164,7 @@ impl KclValue {
11561164
PrimitiveType::Any => Ok(self.clone()),
11571165
PrimitiveType::Number(ty) => {
11581166
if convert_units {
1159-
return ty.coerce(self);
1167+
return ty.coerce(self, exec_state);
11601168
}
11611169

11621170
// Instead of converting units, reinterpret the number as having
@@ -1172,10 +1180,10 @@ impl KclValue {
11721180
value: *n,
11731181
meta: meta.clone(),
11741182
};
1175-
return ty.coerce(&value);
1183+
return ty.coerce(&value, exec_state);
11761184
}
11771185
}
1178-
ty.coerce(self)
1186+
ty.coerce(self, exec_state)
11791187
}
11801188
PrimitiveType::String => match self {
11811189
KclValue::String { .. } => Ok(self.clone()),

0 commit comments

Comments
 (0)