diff --git a/Cargo.lock b/Cargo.lock index a41b95749d0..bbf4c625348 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3741,6 +3741,7 @@ dependencies = [ "quickcheck", "quickcheck_macros", "roc_collections", + "roc_error_macros", "roc_module", "roc_region", ] diff --git a/crates/compiler/can/src/expr.rs b/crates/compiler/can/src/expr.rs index bc4d38b3c10..e0e527d3990 100644 --- a/crates/compiler/can/src/expr.rs +++ b/crates/compiler/can/src/expr.rs @@ -1378,31 +1378,31 @@ pub fn canonicalize_expr<'a>( // Below this point, we shouln't see any of these nodes anymore because // operator desugaring should have removed them! bad_expr @ ast::Expr::ParensAround(_) => { - panic!( + internal_error!( "A ParensAround did not get removed during operator desugaring somehow: {:#?}", bad_expr ); } bad_expr @ ast::Expr::SpaceBefore(_, _) => { - panic!( + internal_error!( "A SpaceBefore did not get removed during operator desugaring somehow: {:#?}", bad_expr ); } bad_expr @ ast::Expr::SpaceAfter(_, _) => { - panic!( + internal_error!( "A SpaceAfter did not get removed during operator desugaring somehow: {:#?}", bad_expr ); } bad_expr @ ast::Expr::BinOps { .. } => { - panic!( + internal_error!( "A binary operator chain did not get desugared somehow: {:#?}", bad_expr ); } bad_expr @ ast::Expr::UnaryOp(_, _) => { - panic!( + internal_error!( "A unary operator did not get desugared somehow: {:#?}", bad_expr ); @@ -1814,7 +1814,7 @@ fn canonicalize_field<'a>( // A label with no value, e.g. `{ name }` (this is sugar for { name: name }) LabelOnly(_) => { - panic!("Somehow a LabelOnly record field was not desugared!"); + internal_error!("Somehow a LabelOnly record field was not desugared!"); } SpaceBefore(sub_field, _) | SpaceAfter(sub_field, _) => { @@ -1822,7 +1822,7 @@ fn canonicalize_field<'a>( } Malformed(_string) => { - panic!("TODO canonicalize malformed record field"); + internal_error!("TODO canonicalize malformed record field"); } } } diff --git a/crates/compiler/can/src/module.rs b/crates/compiler/can/src/module.rs index 2f8eb3dd11b..6c04bbce0cb 100644 --- a/crates/compiler/can/src/module.rs +++ b/crates/compiler/can/src/module.rs @@ -338,7 +338,7 @@ pub fn canonicalize_module_defs<'a>( can_exposed_imports.insert(symbol, region); } Err((_shadowed_symbol, _region)) => { - panic!("TODO gracefully handle shadowing in imports.") + internal_error!("TODO gracefully handle shadowing in imports.") } } } else { @@ -359,7 +359,7 @@ pub fn canonicalize_module_defs<'a>( // here we do nothing special } Err((shadowed_symbol, _region)) => { - panic!( + internal_error!( "TODO gracefully handle shadowing in imports, {:?} is shadowed.", shadowed_symbol ) @@ -523,7 +523,7 @@ pub fn canonicalize_module_defs<'a>( GeneratedInfo::Builtin => { match crate::builtins::builtin_defs_map(*symbol, var_store) { None => { - panic!("A builtin module contains a signature without implementation for {:?}", symbol) + internal_error!("A builtin module contains a signature without implementation for {:?}", symbol) } Some(replacement_def) => { declarations.update_builtin_def(index, replacement_def); @@ -581,7 +581,7 @@ pub fn canonicalize_module_defs<'a>( GeneratedInfo::Builtin => { match crate::builtins::builtin_defs_map(*symbol, var_store) { None => { - panic!("A builtin module contains a signature without implementation for {:?}", symbol) + internal_error!("A builtin module contains a signature without implementation for {:?}", symbol) } Some(replacement_def) => { declarations.update_builtin_def(index, replacement_def); diff --git a/crates/compiler/can/src/operator.rs b/crates/compiler/can/src/operator.rs index 39d82d196c2..37071d5ba01 100644 --- a/crates/compiler/can/src/operator.rs +++ b/crates/compiler/can/src/operator.rs @@ -2,6 +2,7 @@ use bumpalo::collections::Vec; use bumpalo::Bump; +use roc_error_macros::internal_error; use roc_module::called_via::BinOp::Pizza; use roc_module::called_via::{BinOp, CalledVia}; use roc_module::ident::ModuleName; @@ -592,7 +593,7 @@ fn binop_step<'a>( // // By design, Roc neither allows custom operators nor has any built-in operators with // the same precedence and different associativity, so this should never happen! - panic!("BinOps had the same associativity, but different precedence. This should never happen!"); + internal_error!("BinOps had the same associativity, but different precedence. This should never happen!"); } } } diff --git a/crates/compiler/can/src/scope.rs b/crates/compiler/can/src/scope.rs index 18b9c651fe7..d1f4656ba7a 100644 --- a/crates/compiler/can/src/scope.rs +++ b/crates/compiler/can/src/scope.rs @@ -1,4 +1,5 @@ use roc_collections::{VecMap, VecSet}; +use roc_error_macros::internal_error; use roc_module::ident::Ident; use roc_module::symbol::{IdentId, IdentIds, ModuleId, Symbol}; use roc_problem::can::RuntimeError; @@ -470,9 +471,13 @@ pub fn create_alias( } if !hidden.is_empty() { - panic!( + internal_error!( "Found unbound type variables {:?} \n in type alias {:?} {:?} {:?} : {:?}", - hidden, name, &vars, &infer_ext_in_output_variables, &typ + hidden, + name, + &vars, + &infer_ext_in_output_variables, + &typ ) } diff --git a/crates/compiler/can/src/string.rs b/crates/compiler/can/src/string.rs index bb69adf4ff5..5d2c344223e 100644 --- a/crates/compiler/can/src/string.rs +++ b/crates/compiler/can/src/string.rs @@ -1,6 +1,7 @@ // use bumpalo::collections::string::String; // use bumpalo::collections::vec::Vec; use bumpalo::Bump; +use roc_error_macros::internal_error; use roc_parse::ast::Expr; // use roc_parse::ast::{Attempting, Expr}; // use roc_parse::ident; @@ -12,7 +13,7 @@ use roc_region::all::Region; // use std::iter::Peekable; pub fn canonical_string_literal<'a>(_arena: &Bump, _raw: &'a str, _region: Region) -> Expr<'a> { - panic!("TODO restore canonicalization"); + internal_error!("TODO restore canonicalization"); } // let mut problems = std::vec::Vec::new(); diff --git a/crates/compiler/parse/Cargo.toml b/crates/compiler/parse/Cargo.toml index dbb2ca21c1e..696a75f72bb 100644 --- a/crates/compiler/parse/Cargo.toml +++ b/crates/compiler/parse/Cargo.toml @@ -14,6 +14,7 @@ version.workspace = true roc_collections = { path = "../collections" } roc_module = { path = "../module" } roc_region = { path = "../region" } +roc_error_macros = { path = "../../error_macros" } bumpalo.workspace = true encode_unicode.workspace = true diff --git a/crates/compiler/parse/src/expr.rs b/crates/compiler/parse/src/expr.rs index 930ca26c400..7f5b2890831 100644 --- a/crates/compiler/parse/src/expr.rs +++ b/crates/compiler/parse/src/expr.rs @@ -21,6 +21,7 @@ use crate::type_annotation; use bumpalo::collections::Vec; use bumpalo::Bump; use roc_collections::soa::Slice; +use roc_error_macros::internal_error; use roc_module::called_via::{BinOp, CalledVia, UnaryOp}; use roc_region::all::{Loc, Position, Region}; @@ -2479,10 +2480,10 @@ fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> { // TODO: make this state impossible to represent in Ident::Access, // by splitting out parts[0] into a separate field with a type of `&'a str`, // rather than a `&'a [Accessor<'a>]`. - panic!("Parsed an Ident::Access with a first part of a tuple index"); + internal_error!("Parsed an Ident::Access with a first part of a tuple index"); } None => { - panic!("Parsed an Ident::Access with no parts"); + internal_error!("Parsed an Ident::Access with no parts"); } };