From 2c298c72471fb271190a74b6c1fd524c831de141 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 19 Aug 2018 21:40:30 -0700 Subject: [PATCH] Add warning for undefined operator In practice this will probably always not typecheck, but it's a valid parse --- schala-lang/src/builtin.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/schala-lang/src/builtin.rs b/schala-lang/src/builtin.rs index 32b3d73..61f0400 100644 --- a/schala-lang/src/builtin.rs +++ b/schala-lang/src/builtin.rs @@ -73,7 +73,11 @@ impl BinOp { RAngleBracket => ">", _ => return None }; - Some(BINOPS.get(s).map(|x| x.2.clone()).expect("Custom operators not handled yet")) + let default = 10_000_000; + Some(BINOPS.get(s).map(|x| x.2.clone()).unwrap_or_else(|| { + println!("Warning: operator {} not defined", s); + default + })) } } @@ -128,5 +132,6 @@ lazy_static! { "<" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20), "<=" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20), "==" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20), + "=" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20), }; }