Skip to content

Commit 908d6c7

Browse files
JasperDeSutteralerque
authored andcommitted
refactor(fluent-bundle): Remove unreachable MissingDefault ResolverError
1 parent 6039091 commit 908d6c7

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

fluent-bundle/src/resolver/errors.rs

-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ where
5353
pub enum ResolverError {
5454
Reference(ReferenceKind),
5555
NoValue(String),
56-
MissingDefault,
5756
Cyclic,
5857
TooManyPlaceables,
5958
}
@@ -82,7 +81,6 @@ impl std::fmt::Display for ResolverError {
8281
ReferenceKind::Variable { id } => write!(f, "Unknown variable: ${}", id),
8382
},
8483
Self::NoValue(id) => write!(f, "No value: {}", id),
85-
Self::MissingDefault => f.write_str("No default"),
8684
Self::Cyclic => f.write_str("Cyclical dependency detected"),
8785
Self::TooManyPlaceables => f.write_str("Too many placeables"),
8886
}

fluent-bundle/src/resolver/expression.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::fmt;
77
use fluent_syntax::ast;
88

99
use crate::memoizer::MemoizerKind;
10-
use crate::resolver::{ResolveValue, ResolverError};
10+
use crate::resolver::ResolveValue;
1111
use crate::resource::FluentResource;
1212
use crate::types::FluentValue;
1313

@@ -43,13 +43,12 @@ impl<'bundle> WriteValue<'bundle> for ast::Expression<&'bundle str> {
4343
_ => {}
4444
}
4545

46-
for variant in variants {
47-
if variant.default {
48-
return variant.value.write(w, scope);
49-
}
50-
}
51-
scope.add_error(ResolverError::MissingDefault);
52-
Ok(())
46+
variants
47+
.iter()
48+
.find(|variant| variant.default)
49+
.expect("select expressions have a default variant")
50+
.value
51+
.write(w, scope)
5352
}
5453
}
5554
}
@@ -95,13 +94,12 @@ impl<'bundle> ResolveValue<'bundle> for ast::Expression<&'bundle str> {
9594
_ => {}
9695
}
9796

98-
for variant in variants {
99-
if variant.default {
100-
return variant.value.resolve(scope);
101-
}
102-
}
103-
scope.add_error(ResolverError::MissingDefault);
104-
FluentValue::Error
97+
variants
98+
.iter()
99+
.find(|variant| variant.default)
100+
.expect("select expressions have a default variant")
101+
.value
102+
.resolve(scope)
105103
}
106104
}
107105
}

fluent-bundle/tests/resolver_fixtures.rs

-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ fn test_errors(errors: &[FluentError], reference: Option<&[TestError]>) {
334334
ResolverError::TooManyPlaceables => {
335335
assert_eq!(reference.error_type, "TooManyPlaceables");
336336
}
337-
_ => unimplemented!(),
338337
},
339338
FluentError::ParserError(_) => {
340339
assert_eq!(reference.error_type, "Parser");

fluent-syntax/src/ast/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,7 @@ pub enum Expression<S> {
14441444
/// [key1] Value 1
14451445
/// *[other] Value 2
14461446
/// }
1447+
/// Invariant: exactly 1 variant must have default: true.
14471448
/// ```
14481449
Select {
14491450
selector: InlineExpression<S>,

0 commit comments

Comments
 (0)