Skip to content

Commit 349544a

Browse files
committed
More warnings
Signed-off-by: Nick Cameron <[email protected]>
1 parent 20c074d commit 349544a

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()),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ async fn inner_extrude(
105105
(Some(angle), angle_step, center) => {
106106
let center = center.clone().map(point_to_mm).map(Point2d::from).unwrap_or_default();
107107
let total_rotation_angle = Angle::from_degrees(angle.to_degrees(exec_state, args.source_range));
108-
let angle_step_size = Angle::from_degrees(angle_step.clone().map(|a| a.to_degrees(exec_state, args.source_range)).unwrap_or(15.0));
108+
let angle_step_size = Angle::from_degrees(
109+
angle_step
110+
.clone()
111+
.map(|a| a.to_degrees(exec_state, args.source_range))
112+
.unwrap_or(15.0),
113+
);
109114
ModelingCmd::from(mcmd::TwistExtrude {
110115
target: sketch.id.into(),
111116
distance: LengthUnit(length.to_mm()),

src/lang/std/sketch.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
createCallExpressionStdLibKw,
3232
createLabeledArg,
3333
createLiteral,
34-
createLiteralMaybeSuffix,
3534
createLocalName,
3635
createPipeExpression,
3736
createTagDeclarator,
@@ -4227,13 +4226,8 @@ const tangentialArcHelpers = {
42274226
callExpression,
42284227
createLiteral(roundOff(radius, 2))
42294228
)
4230-
const angleValue = createLiteralMaybeSuffix({
4231-
value: roundOff(angle, 2),
4232-
suffix: 'Deg',
4233-
})
4234-
if (!err(angleValue)) {
4235-
mutateKwArg(ARG_ANGLE, callExpression, angleValue)
4236-
}
4229+
const angleValue = createLiteral(roundOff(angle, 2), 'Deg')
4230+
mutateKwArg(ARG_ANGLE, callExpression, angleValue)
42374231
} else {
42384232
console.debug('Invalid center calculated for tangential arc')
42394233
}

src/machines/modelingMachine.test.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -376,45 +376,53 @@ p3 = [342.51, 216.38],
376376
namedConstantConstraint: [
377377
{
378378
name: 'should constrain angledLine, angle value',
379-
...makeStraightSegmentSnippet('angledLine(angle = 45, length = 100)'),
379+
...makeStraightSegmentSnippet(
380+
'angledLine(angle = 45deg, length = 100)'
381+
),
380382
constraintIndex: 0,
381383
expectedResult: 'angledLine(angle = test_variable, length = 100)',
382384
},
383385
{
384386
name: 'should constrain angledLine, length value',
385-
...makeStraightSegmentSnippet('angledLine(angle = 45, length = 100)'),
387+
...makeStraightSegmentSnippet(
388+
'angledLine(angle = 45deg, length = 100)'
389+
),
386390
constraintIndex: 1,
387-
expectedResult: 'angledLine(angle = 45, length = test_variable)',
391+
expectedResult: 'angledLine(angle = 45deg, length = test_variable)',
388392
},
389393
{
390394
name: 'should constrain angledLine, endAbsoluteY value',
391395
...makeStraightSegmentSnippet(
392-
'angledLine(angle = 45, endAbsoluteY = 5)'
396+
'angledLine(angle = 45deg, endAbsoluteY = 5)'
393397
),
394398
constraintIndex: 1,
395399
expectedResult:
396-
'angledLine(angle = 45, endAbsoluteY = test_variable)',
400+
'angledLine(angle = 45deg, endAbsoluteY = test_variable)',
397401
},
398402
{
399403
name: 'should constrain angledLine, endAbsoluteX value',
400404
...makeStraightSegmentSnippet(
401-
'angledLine(angle = 45, endAbsoluteX = 5)'
405+
'angledLine(angle = 45deg, endAbsoluteX = 5)'
402406
),
403407
constraintIndex: 1,
404408
expectedResult:
405-
'angledLine(angle = 45, endAbsoluteX = test_variable)',
409+
'angledLine(angle = 45deg, endAbsoluteX = test_variable)',
406410
},
407411
{
408412
name: 'should constrain angledLine, lengthY value',
409-
...makeStraightSegmentSnippet('angledLine(angle = 45, lengthY = 5)'),
413+
...makeStraightSegmentSnippet(
414+
'angledLine(angle = 45deg, lengthY = 5)'
415+
),
410416
constraintIndex: 1,
411-
expectedResult: 'angledLine(angle = 45, lengthY = test_variable)',
417+
expectedResult: 'angledLine(angle = 45deg, lengthY = test_variable)',
412418
},
413419
{
414420
name: 'should constrain angledLine, lengthX value',
415-
...makeStraightSegmentSnippet('angledLine(angle = 45, lengthX = 5)'),
421+
...makeStraightSegmentSnippet(
422+
'angledLine(angle = 45deg, lengthX = 5)'
423+
),
416424
constraintIndex: 1,
417-
expectedResult: 'angledLine(angle = 45, lengthX = test_variable)',
425+
expectedResult: 'angledLine(angle = 45deg, lengthX = test_variable)',
418426
},
419427
],
420428
removeAllConstraintsCases: [
@@ -466,7 +474,7 @@ p3 = [342.51, 216.38],
466474
'angledLine(angle = testVar1, length = testVar2)'
467475
),
468476
constraintIndex: 0,
469-
expectedResult: 'angledLine(angle = 55, length = testVar2)',
477+
expectedResult: 'angledLine(angle = 55deg, length = testVar2)',
470478
},
471479
{
472480
name: 'should un-constrain angledLine, length value',
@@ -512,27 +520,33 @@ p3 = [342.51, 216.38],
512520
deleteSegment: [
513521
{
514522
name: 'should delete angledLine, angle length',
515-
...makeStraightSegmentSnippet('angledLine(angle = 45, length = 100)'),
523+
...makeStraightSegmentSnippet(
524+
'angledLine(angle = 45deg, length = 100)'
525+
),
516526
},
517527
{
518528
name: 'should delete angledLine, endAbsoluteY',
519529
...makeStraightSegmentSnippet(
520-
'angledLine(angle = 45, endAbsoluteY = 5)'
530+
'angledLine(angle = 45deg, endAbsoluteY = 5)'
521531
),
522532
},
523533
{
524534
name: 'should delete angledLine, endAbsoluteX',
525535
...makeStraightSegmentSnippet(
526-
'angledLine(angle = 45, endAbsoluteX = 5)'
536+
'angledLine(angle = 45deg, endAbsoluteX = 5)'
527537
),
528538
},
529539
{
530540
name: 'should delete angledLine, lengthY',
531-
...makeStraightSegmentSnippet('angledLine(angle = 45, lengthY = 5)'),
541+
...makeStraightSegmentSnippet(
542+
'angledLine(angle = 45deg, lengthY = 5)'
543+
),
532544
},
533545
{
534546
name: 'should delete angledLine, lengthX',
535-
...makeStraightSegmentSnippet('angledLine(angle = 45, lengthX = 5)'),
547+
...makeStraightSegmentSnippet(
548+
'angledLine(angle = 45deg, lengthX = 5)'
549+
),
536550
},
537551
],
538552
},

0 commit comments

Comments
 (0)