@@ -4,7 +4,10 @@ use annotate_snippets::{
4
4
} ;
5
5
use fluent_bundle:: { FluentBundle , FluentError , FluentResource } ;
6
6
use fluent_syntax:: {
7
- ast:: { Attribute , Entry , Identifier , Message } ,
7
+ ast:: {
8
+ Attribute , Entry , Expression , Identifier , InlineExpression , Message , Pattern ,
9
+ PatternElement ,
10
+ } ,
8
11
parser:: ParserError ,
9
12
} ;
10
13
use proc_macro:: { Diagnostic , Level , Span } ;
@@ -185,9 +188,12 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
185
188
} ;
186
189
187
190
let mut constants = TokenStream :: new ( ) ;
191
+ let mut messagerefs = Vec :: new ( ) ;
188
192
for entry in resource. entries ( ) {
189
193
let span = res. krate . span ( ) ;
190
- if let Entry :: Message ( Message { id : Identifier { name } , attributes, .. } ) = entry {
194
+ if let Entry :: Message ( Message { id : Identifier { name } , attributes, value, .. } ) =
195
+ entry
196
+ {
191
197
let _ = previous_defns. entry ( name. to_string ( ) ) . or_insert ( path_span) ;
192
198
193
199
if name. contains ( '-' ) {
@@ -200,6 +206,18 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
200
206
. emit ( ) ;
201
207
}
202
208
209
+ if let Some ( Pattern { elements } ) = value {
210
+ for elt in elements {
211
+ if let PatternElement :: Placeable {
212
+ expression :
213
+ Expression :: Inline ( InlineExpression :: MessageReference { id, .. } ) ,
214
+ } = elt
215
+ {
216
+ messagerefs. push ( ( id. name , * name) ) ;
217
+ }
218
+ }
219
+ }
220
+
203
221
// Require that the message name starts with the crate name
204
222
// `hir_typeck_foo_bar` (in `hir_typeck.ftl`)
205
223
// `const_eval_baz` (in `const_eval.ftl`)
@@ -258,6 +276,18 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
258
276
}
259
277
}
260
278
279
+ for ( mref, name) in messagerefs. into_iter ( ) {
280
+ if !previous_defns. contains_key ( mref) {
281
+ Diagnostic :: spanned (
282
+ path_span,
283
+ Level :: Error ,
284
+ format ! ( "referenced message `{mref}` does not exist (in message `{name}`)" ) ,
285
+ )
286
+ . help ( & format ! ( "you may have meant to use a variable reference (`{{${mref}}}`)" ) )
287
+ . emit ( ) ;
288
+ }
289
+ }
290
+
261
291
if let Err ( errs) = bundle. add_resource ( resource) {
262
292
for e in errs {
263
293
match e {
0 commit comments