tamer: asg::air::air: Eliminate todo! for unexpected AirIdent

I had apparently forgotten about this, because I didn't benefit from the
exhaustiveness check; this needs to be eliminated so that this doesn't
happen again, and to provide a proper non-panicking error.

DEV-13162
main
Mike Gerwitz 2023-05-08 15:50:44 -04:00
parent 4ec4857360
commit 5f275fb801
3 changed files with 34 additions and 1 deletions

View File

@ -310,7 +310,9 @@ impl ParseState for AirAggregate {
Transition(Toplevel(oi_pkg)).incomplete()
}
(st, tok @ AirIdent(..)) => todo!("{st:?}, {tok:?}"),
(st @ (Empty | PkgExpr(..) | PkgTpl(..)), AirIdent(tok)) => {
Transition(st).err(AsgError::UnexpectedOpaqueIdent(tok.name()))
}
}
}

View File

@ -825,3 +825,18 @@ sum_ir! {
/// Tokens that may be used to define or apply templates.
pub sum enum AirBindableTpl = AirTpl | AirBind | AirDoc;
}
impl AirIdent {
/// Name of the identifier described by this token.
pub fn name(&self) -> SPair {
use AirIdent::*;
match self {
IdentDecl(name, _, _)
| IdentExternDecl(name, _, _)
| IdentDep(name, _)
| IdentFragment(name, _)
| IdentRoot(name) => *name,
}
}
}

View File

@ -155,6 +155,9 @@ pub enum AsgError {
/// depends on first having computed itself,
/// which is not possible.
UnsupportedCycle(Cycle),
/// An opaque identifier was declared in an invalid context.
UnexpectedOpaqueIdent(SPair),
}
impl Display for AsgError {
@ -212,6 +215,13 @@ impl Display for AsgError {
UnsupportedCycle(cycle) => {
write!(f, "circular dependency: {cycle}")
}
UnexpectedOpaqueIdent(name) => {
write!(
f,
"opaque identifier {} declaration",
TtQuote::wrap(name)
)
}
}
}
}
@ -371,6 +381,12 @@ impl Diagnostic for AsgError {
desc
}
// TODO: This doesn't seem all that helpful.
// What are the circumstances under which this can be hit,
// and what additional information can we provide?
UnexpectedOpaqueIdent(name) => vec![name.error(
"an opaque identifier declaration was not expected here",
)],
}
}
}