Give an error instead of panicking on an empty tuple type

This commit is contained in:
Joshua Warner 2024-12-08 10:11:15 -08:00
parent 861f9c5d47
commit cbd6d50584
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 35 additions and 25 deletions

View file

@ -9,7 +9,7 @@ use crate::scope::{PendingAbilitiesInScope, Scope};
use roc_exhaustive::ListArity;
use roc_module::ident::{Ident, Lowercase, TagName};
use roc_module::symbol::Symbol;
use roc_parse::ast::{self, StrLiteral, StrSegment};
use roc_parse::ast::{self, ExtractSpaces, StrLiteral, StrSegment};
use roc_parse::pattern::PatternType;
use roc_problem::can::{MalformedPatternProblem, Problem, RuntimeError, ShadowKind};
use roc_region::all::{Loc, Region};
@ -476,7 +476,14 @@ pub fn canonicalize_pattern<'a>(
Pattern::OpaqueNotInScope(Loc::at(tag.region, name.into()))
}
},
_ => unreachable!("Other patterns cannot be applied"),
_ => {
env.problem(Problem::RuntimeError(RuntimeError::MalformedPattern(
MalformedPatternProblem::CantApplyPattern,
tag.region,
)));
Pattern::UnsupportedPattern(region)
}
}
}
@ -817,7 +824,7 @@ pub fn canonicalize_record_destructs<'a>(
let mut opt_erroneous = None;
for loc_pattern in patterns.iter() {
match loc_pattern.value {
match loc_pattern.value.extract_spaces().item {
Identifier { ident: label } => {
match scope.introduce(label.into(), region) {
Ok(symbol) => {