Skip to content

Commit

Permalink
refactor(fluent-bundle): Remove unreachable MissingDefault ResolverError
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperDeSutter authored and alerque committed May 6, 2024
1 parent fc9858b commit b3b2124
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 0 additions & 2 deletions fluent-bundle/src/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ where
pub enum ResolverError {
Reference(ReferenceKind),
NoValue(String),
MissingDefault,
Cyclic,
TooManyPlaceables,
}
Expand Down Expand Up @@ -82,7 +81,6 @@ impl std::fmt::Display for ResolverError {
ReferenceKind::Variable { id } => write!(f, "Unknown variable: ${}", id),
},
Self::NoValue(id) => write!(f, "No value: {}", id),
Self::MissingDefault => f.write_str("No default"),
Self::Cyclic => f.write_str("Cyclical dependency detected"),
Self::TooManyPlaceables => f.write_str("Too many placeables"),
}
Expand Down
28 changes: 13 additions & 15 deletions fluent-bundle/src/resolver/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fmt;
use fluent_syntax::ast;

use crate::memoizer::MemoizerKind;
use crate::resolver::{ResolveValue, ResolverError};
use crate::resolver::ResolveValue;
use crate::resource::FluentResource;
use crate::types::FluentValue;

Expand Down Expand Up @@ -43,13 +43,12 @@ impl<'bundle> WriteValue<'bundle> for ast::Expression<&'bundle str> {
_ => {}
}

for variant in variants {
if variant.default {
return variant.value.write(w, scope);
}
}
scope.add_error(ResolverError::MissingDefault);
Ok(())
variants
.iter()
.find(|variant| variant.default)
.expect("select expressions have a default variant")
.value
.write(w, scope)
}
}
}
Expand Down Expand Up @@ -95,13 +94,12 @@ impl<'bundle> ResolveValue<'bundle> for ast::Expression<&'bundle str> {
_ => {}
}

for variant in variants {
if variant.default {
return variant.value.resolve(scope);
}
}
scope.add_error(ResolverError::MissingDefault);
FluentValue::Error
variants
.iter()
.find(|variant| variant.default)
.expect("select expressions have a default variant")
.value
.resolve(scope)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion fluent-bundle/tests/resolver_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ fn test_errors(errors: &[FluentError], reference: Option<&[TestError]>) {
ResolverError::TooManyPlaceables => {
assert_eq!(reference.error_type, "TooManyPlaceables");
}
_ => unimplemented!(),
},
FluentError::ParserError(_) => {
assert_eq!(reference.error_type, "Parser");
Expand Down
1 change: 1 addition & 0 deletions fluent-syntax/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ pub enum Expression<S> {
/// [key1] Value 1
/// *[other] Value 2
/// }
/// Invariant: exactly 1 variant must have default: true.
/// ```
Select {
selector: InlineExpression<S>,
Expand Down

0 comments on commit b3b2124

Please sign in to comment.