Skip to content

Commit 2152d19

Browse files
committed
Warn if exactly one of manufacturer or mpn is set (XOR)
1 parent ca9e69c commit 2152d19

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

crates/pcb-sch/src/physical.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3622,7 +3622,6 @@ mod tests {
36223622

36233623
let heap = Heap::new();
36243624
let range = heap.alloc(physical_range(3.0, 3.6, PhysicalUnit::Volts));
3625-
let gnd_str = heap.alloc("0V");
36263625

36273626
// Get the range from heap
36283627
let range_val = range.downcast_ref::<PhysicalRange>().unwrap();

crates/pcb-zen-core/src/lang/component.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,30 @@ where
10601060
.map(|s| s.to_owned())
10611061
});
10621062

1063+
// Warn if exactly one of manufacturer or mpn is set (XOR)
1064+
if final_manufacturer.is_some() != final_mpn.is_some() {
1065+
if let Some(call_site) = eval_ctx.call_stack_top_location() {
1066+
use crate::Diagnostic;
1067+
use starlark::errors::EvalSeverity;
1068+
let body = if final_manufacturer.is_some() {
1069+
"MPN must be specified if manufacturer is specified"
1070+
} else {
1071+
"Manufacturer must be specified if MPN is specified"
1072+
};
1073+
let diag = Diagnostic {
1074+
path: call_site.filename().to_string(),
1075+
span: Some(call_site.resolve_span()),
1076+
severity: EvalSeverity::Warning,
1077+
body: body.to_string(),
1078+
call_stack: None,
1079+
child: None,
1080+
source_error: None,
1081+
suppressed: false,
1082+
};
1083+
eval_ctx.add_diagnostic(diag);
1084+
}
1085+
}
1086+
10631087
// If datasheet is not explicitly provided, try to get it from properties, then symbol properties
10641088
// Skip empty strings and "~" (KiCad's placeholder for no datasheet) - prefer None over empty
10651089
let final_datasheet = datasheet_val

crates/pcb-zen-core/tests/snapshots/component__component_manufacturer_from_symbol.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
source: crates/pcb-zen-core/tests/component.rs
33
expression: output
44
---
5+
Warning: test.zen:2:1-10:2 MPN must be specified if manufacturer is specified
56
{
67
<root>: Module {
78
path: <root>,

crates/pcb-zen-core/tests/snapshots/component__component_with_manufacturer.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
source: crates/pcb-zen-core/tests/component.rs
33
expression: output
44
---
5+
Warning: test.zen:2:1-14:2 MPN must be specified if manufacturer is specified
56
{
67
<root>: Module {
78
path: <root>,

0 commit comments

Comments
 (0)