Skip to content

Commit 2f348f4

Browse files
committed
ICU-22902 Remove support for Unsupported, Private & Reserved constructs
Matching PR unicode-org#883 in the message-format-wg repo. Also move spec tests for unsupported statements and expressions into new files to serve as syntax error tests.
1 parent 5f9f8b2 commit 2f348f4

20 files changed

+109
-1577
lines changed

icu4c/source/common/unicode/utypes.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,15 +597,13 @@ typedef enum UErrorCode {
597597
U_MF_MISSING_SELECTOR_ANNOTATION_ERROR, /**< A selector expression evaluates to an unannotated operand. @internal ICU 75 technology preview @deprecated This API is for technology preview only. */
598598
U_MF_DUPLICATE_DECLARATION_ERROR, /**< The same variable is declared in more than one .local or .input declaration. @internal ICU 75 technology preview @deprecated This API is for technology preview only. */
599599
U_MF_OPERAND_MISMATCH_ERROR, /**< An operand provided to a function does not have the required form for that function @internal ICU 75 technology preview @deprecated This API is for technology preview only. */
600-
U_MF_UNSUPPORTED_STATEMENT_ERROR, /**< A message includes a reserved statement. @internal ICU 75 technology preview @deprecated This API is for technology preview only. */
601-
U_MF_UNSUPPORTED_EXPRESSION_ERROR, /**< A message includes syntax reserved for future standardization or private implementation use. @internal ICU 75 technology preview @deprecated This API is for technology preview only. */
602600
U_MF_DUPLICATE_VARIANT_ERROR, /**< A message includes a variant with the same key list as another variant. @internal ICU 76 technology preview @deprecated This API is for technology preview only. */
603601
#ifndef U_HIDE_DEPRECATED_API
604602
/**
605603
* One more than the highest normal formatting API error code.
606604
* @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
607605
*/
608-
U_FMT_PARSE_ERROR_LIMIT = 0x10122,
606+
U_FMT_PARSE_ERROR_LIMIT = 0x10120,
609607
#endif // U_HIDE_DEPRECATED_API
610608

611609
/*

icu4c/source/common/utypes.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ _uFmtErrorName[U_FMT_PARSE_ERROR_LIMIT - U_FMT_PARSE_ERROR_START] = {
140140
"U_MF_MISSING_SELECTOR_ANNOTATION_ERROR",
141141
"U_MF_DUPLICATE_DECLARATION_ERROR",
142142
"U_MF_OPERAND_MISMATCH_ERROR",
143-
"U_MF_UNSUPPORTED_STATEMENT_ERROR",
144-
"U_MF_UNSUPPORTED_EXPRESSION_ERROR",
145143
"U_MF_DUPLICATE_VARIANT_ERROR"
146144
};
147145

icu4c/source/i18n/messageformat2.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,6 @@ FunctionOptions MessageFormatter::resolveOptions(const Environment& env, const O
241241
return FormattedPlaceholder(fallback);
242242
}
243243

244-
// Per https://github.com/unicode-org/message-format-wg/blob/main/spec/formatting.md#fallback-resolution
245-
static UnicodeString reservedFallback (const Expression& e) {
246-
UErrorCode localErrorCode = U_ZERO_ERROR;
247-
const Operator* rator = e.getOperator(localErrorCode);
248-
U_ASSERT(U_SUCCESS(localErrorCode));
249-
const Reserved& r = rator->asReserved();
250-
251-
// An empty Reserved isn't representable in the syntax
252-
U_ASSERT(r.numParts() > 0);
253-
254-
const UnicodeString& contents = r.getPart(0).unquoted();
255-
// Parts should never be empty
256-
U_ASSERT(contents.length() > 0);
257-
258-
// Return first character of string
259-
return UnicodeString(contents, 0, 1);
260-
}
261-
262244
// Formats an expression using `globalEnv` for the values of variables
263245
[[nodiscard]] FormattedPlaceholder MessageFormatter::formatExpression(const Environment& globalEnv,
264246
const Expression& expr,
@@ -268,12 +250,6 @@ static UnicodeString reservedFallback (const Expression& e) {
268250
return {};
269251
}
270252

271-
// Formatting error
272-
if (expr.isReserved()) {
273-
context.getErrors().setReservedError(status);
274-
return FormattedPlaceholder(reservedFallback(expr));
275-
}
276-
277253
const Operand& rand = expr.getOperand();
278254
// Format the operand (formatOperand handles the case of a null operand)
279255
FormattedPlaceholder randVal = formatOperand(globalEnv, rand, context, status);
@@ -675,12 +651,6 @@ ResolvedSelector MessageFormatter::resolveVariables(const Environment& env,
675651
return {};
676652
}
677653

678-
// A `reserved` is an error
679-
if (expr.isReserved()) {
680-
context.getErrors().setReservedError(status);
681-
return ResolvedSelector(FormattedPlaceholder(reservedFallback(expr)));
682-
}
683-
684654
// Function call -- resolve the operand and options
685655
if (expr.isFunctionCall()) {
686656
const Operator* rator = expr.getOperator(status);

icu4c/source/i18n/messageformat2_checker.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ void Checker::addFreeVars(TypeEnvironment& t, const OptionMap& opts, UErrorCode&
136136
void Checker::addFreeVars(TypeEnvironment& t, const Operator& rator, UErrorCode& status) {
137137
CHECK_ERROR(status);
138138

139-
if (!rator.isReserved()) {
140-
addFreeVars(t, rator.getOptionsInternal(), status);
141-
}
139+
addFreeVars(t, rator.getOptionsInternal(), status);
142140
}
143141

144142
void Checker::addFreeVars(TypeEnvironment& t, const Expression& rhs, UErrorCode& status) {
@@ -213,12 +211,10 @@ void Checker::requireAnnotated(const TypeEnvironment& t, const Expression& selec
213211
if (selectorExpr.isFunctionCall()) {
214212
return; // No error
215213
}
216-
if (!selectorExpr.isReserved()) {
217-
const Operand& rand = selectorExpr.getOperand();
218-
if (rand.isVariable()) {
219-
if (t.get(rand.asVariable()) == TypeEnvironment::Type::Annotated) {
220-
return; // No error
221-
}
214+
const Operand& rand = selectorExpr.getOperand();
215+
if (rand.isVariable()) {
216+
if (t.get(rand.asVariable()) == TypeEnvironment::Type::Annotated) {
217+
return; // No error
222218
}
223219
}
224220
// If this code is reached, an error was detected
@@ -240,9 +236,6 @@ TypeEnvironment::Type typeOf(TypeEnvironment& t, const Expression& expr) {
240236
if (expr.isFunctionCall()) {
241237
return TypeEnvironment::Type::Annotated;
242238
}
243-
if (expr.isReserved()) {
244-
return TypeEnvironment::Type::Unannotated;
245-
}
246239
const Operand& rand = expr.getOperand();
247240
U_ASSERT(!rand.isNull());
248241
if (rand.isLiteral()) {
@@ -296,11 +289,6 @@ void Checker::checkDeclarations(TypeEnvironment& t, UErrorCode& status) {
296289
// Next, extend the type environment with a binding from lhs to its type
297290
t.extend(lhs, typeOf(t, rhs), status);
298291
}
299-
300-
// Check for unsupported statements
301-
if (dataModel.unsupportedStatementsLen > 0) {
302-
errors.addError(StaticErrorType::UnsupportedStatementError, status);
303-
}
304292
}
305293

306294
void Checker::check(UErrorCode& status) {

0 commit comments

Comments
 (0)