From f29d0102e180efae8d602df71e7aab39e9429326 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Thu, 5 Mar 2026 15:01:20 -0800 Subject: [PATCH] fix(compiler): fix type equality check for cons fn --- core/compiler/src/compile.rs | 2 +- core/compiler/src/lib.rs | 26 ++++++++++++++++++++++++++ examples/seq_any/lib.ar | 10 ++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 examples/seq_any/lib.ar diff --git a/core/compiler/src/compile.rs b/core/compiler/src/compile.rs index 4c3d4ce..de66c38 100644 --- a/core/compiler/src/compile.rs +++ b/core/compiler/src/compile.rs @@ -1603,7 +1603,7 @@ impl<'a> AstTransformer for VarIdTyPass<'a> { if args.posargs.len() == 2 { let seqty = Ty::Seq(Box::new(args.posargs[0].ty())); let tailty = args.posargs[1].ty(); - if !(tailty == Ty::SeqNil || tailty == seqty) { + if !(tailty == Ty::SeqNil || self.is_eq_ty(&tailty, &seqty)) { self.errors.push(StaticError { span: self.span(args.posargs[1].span()), kind: StaticErrorKind::IncorrectTy { diff --git a/core/compiler/src/lib.rs b/core/compiler/src/lib.rs index fc0f13d..a136604 100644 --- a/core/compiler/src/lib.rs +++ b/core/compiler/src/lib.rs @@ -49,6 +49,7 @@ mod tests { const ARGON_ROUNDING: &str = concatcp!(EXAMPLES_DIR, "/rounding/lib.ar"); const ARGON_FLIPPED_RECT: &str = concatcp!(EXAMPLES_DIR, "/flipped_rect/lib.ar"); const ARGON_SEQ_BASIC: &str = concatcp!(EXAMPLES_DIR, "/seq_basic/lib.ar"); + const ARGON_SEQ_ANY: &str = concatcp!(EXAMPLES_DIR, "/seq_any/lib.ar"); const ARGON_SEQ_FN: &str = concatcp!(EXAMPLES_DIR, "/seq_fn/lib.ar"); const ARGON_SEQ_RECUR: &str = concatcp!(EXAMPLES_DIR, "/seq_recur/lib.ar"); const ARGON_LUB_MATCH: &str = concatcp!(EXAMPLES_DIR, "/lub_match/lib.ar"); @@ -573,6 +574,31 @@ mod tests { assert_relative_eq!(r.y1.0, 200., epsilon = EPSILON); } + #[test] + fn argon_seq_any() { + let o = parse_workspace_with_std(ARGON_SEQ_ANY); + assert!(o.static_errors().is_empty()); + let ast = o.ast(); + let cells = compile( + &ast, + CompileInput { + cell: &["top"], + args: Vec::new(), + lyp_file: &PathBuf::from(BASIC_LYP), + }, + ); + println!("{cells:#?}"); + let cells = cells.unwrap_valid(); + let cell = &cells.cells[&cells.top]; + assert_eq!(cell.objects.len(), 1); + let r = cell.objects.iter().find_map(|(_, v)| v.get_rect()).unwrap(); + assert_eq!(r.layer.as_ref().unwrap(), "met1"); + assert_relative_eq!(r.x0.0, 0., epsilon = EPSILON); + assert_relative_eq!(r.y0.0, 0., epsilon = EPSILON); + assert_relative_eq!(r.x1.0, 400., epsilon = EPSILON); + assert_relative_eq!(r.y1.0, 200., epsilon = EPSILON); + } + #[test] fn argon_seq_fn() { let o = parse_workspace_with_std(ARGON_SEQ_FN); diff --git a/examples/seq_any/lib.ar b/examples/seq_any/lib.ar new file mode 100644 index 0000000..4848a47 --- /dev/null +++ b/examples/seq_any/lib.ar @@ -0,0 +1,10 @@ +fn prepend(lst: [Any]) -> [Float] { + cons(100., lst) +} + +cell top() { + let r = rect("met1", x0=0., y0=0., x1=400.)!; + let lst = prepend(cons(500., cons(300., cons(800., cons(200., cons(1400., [])))))); + let v = head(tail(tail(tail(tail(lst))))); + eq(r.y1, v); +}