From 5f275fb801f0e7afa082e42e57f2bea6b5e00aca Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 8 May 2023 15:50:44 -0400 Subject: [PATCH] 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 --- tamer/src/asg/air.rs | 4 +++- tamer/src/asg/air/ir.rs | 15 +++++++++++++++ tamer/src/asg/error.rs | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tamer/src/asg/air.rs b/tamer/src/asg/air.rs index 848c5faf..1bfa3418 100644 --- a/tamer/src/asg/air.rs +++ b/tamer/src/asg/air.rs @@ -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())) + } } } diff --git a/tamer/src/asg/air/ir.rs b/tamer/src/asg/air/ir.rs index 0bd4c480..9e61fe3c 100644 --- a/tamer/src/asg/air/ir.rs +++ b/tamer/src/asg/air/ir.rs @@ -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, + } + } +} diff --git a/tamer/src/asg/error.rs b/tamer/src/asg/error.rs index e0a79a7a..c427c40e 100644 --- a/tamer/src/asg/error.rs +++ b/tamer/src/asg/error.rs @@ -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", + )], } } }