@@ -2,7 +2,6 @@ use itertools::Itertools;
2
2
use sway_error:: {
3
3
error:: { CompileError , StructFieldUsageContext } ,
4
4
handler:: { ErrorEmitted , Handler } ,
5
- warning:: { CompileWarning , Warning } ,
6
5
} ;
7
6
use sway_types:: { BaseIdent , Ident , Span , Spanned } ;
8
7
@@ -308,25 +307,13 @@ fn type_check_struct(
308
307
. expect ( "The struct field with the given field name must exist." ) ;
309
308
310
309
if struct_field. is_private ( ) {
311
- // TODO: Uncomment this code and delete the one with warnings once struct field privacy becomes a hard error.
312
- // https://github.com/FuelLabs/sway/issues/5520
313
- // handler.emit_err(CompileError::StructFieldIsPrivate {
314
- // field_name: field_name.into(),
315
- // struct_name: struct_decl.call_path.suffix.clone(),
316
- // field_decl_span: struct_field.name.span(),
317
- // struct_can_be_changed,
318
- // usage_context: StructFieldUsageContext::PatternMatching { has_rest_pattern },
319
- // });
320
- handler. emit_warn ( CompileWarning {
321
- span : field_name. span ( ) ,
322
- warning_content : Warning :: StructFieldIsPrivate {
323
- field_name : field_name. into ( ) ,
324
- struct_name : struct_decl. call_path . suffix . clone ( ) ,
325
- field_decl_span : struct_field. name . span ( ) ,
326
- struct_can_be_changed,
327
- usage_context : StructFieldUsageContext :: PatternMatching {
328
- has_rest_pattern,
329
- } ,
310
+ handler. emit_err ( CompileError :: StructFieldIsPrivate {
311
+ field_name : field_name. into ( ) ,
312
+ struct_name : struct_decl. call_path . suffix . clone ( ) ,
313
+ field_decl_span : struct_field. name . span ( ) ,
314
+ struct_can_be_changed,
315
+ usage_context : StructFieldUsageContext :: PatternMatching {
316
+ has_rest_pattern,
330
317
} ,
331
318
} ) ;
332
319
}
@@ -377,83 +364,48 @@ fn type_check_struct(
377
364
. collect_vec ( )
378
365
} ;
379
366
380
- // TODO: Uncomment this code and delete the one with warnings once struct field privacy becomes a hard error.
381
- // https://github.com/FuelLabs/sway/issues/5520
382
- // handler.emit_err(
383
- // match (is_public_struct_access, all_public_fields_are_matched, only_public_fields_are_matched) {
384
- // // Public access. Only all public fields are matched. All missing fields are private.
385
- // // -> Emit error for the mandatory ignore `..`.
386
- // (true, true, true) => CompileError::MatchStructPatternMustIgnorePrivateFields {
387
- // private_fields: missing_fields(false),
388
- // struct_name: struct_decl.call_path.suffix.clone(),
389
- // struct_decl_span: struct_decl.span(),
390
- // all_fields_are_private: struct_decl.has_only_private_fields(),
391
- // span: span.clone(),
392
- // },
393
-
394
- // // Public access. All public fields are matched. Some private fields are matched.
395
- // // -> Do not emit error here because it is already covered when reporting private field.
396
- // (true, true, false) => unreachable!("The above if condition eliminates this case."),
397
-
398
- // // Public access. Some or non of the public fields are matched. Some or none of the private fields are matched.
399
- // // -> Emit error listing only missing public fields. Recommendation for mandatory use of `..` is already given
400
- // // when reporting the inaccessible private field.
401
- // // or
402
- // // In struct decl module access. We do not distinguish between private and public fields here.
403
- // // -> Emit error listing all missing fields.
404
- // (true, false, _) | (false, _, _) => CompileError::MatchStructPatternMissingFields {
405
- // missing_fields: missing_fields(is_public_struct_access),
406
- // missing_fields_are_public: is_public_struct_access,
407
- // struct_name: struct_decl.call_path.suffix.clone(),
408
- // struct_decl_span: struct_decl.span(),
409
- // total_number_of_fields: struct_decl.fields.len(),
410
- // span: span.clone(),
411
- // },
412
- // });
413
-
414
- match (
415
- is_public_struct_access,
416
- all_public_fields_are_matched,
417
- only_public_fields_are_matched,
418
- ) {
419
- // Public access. Only all public fields are matched. All missing fields are private.
420
- // -> Emit error for the mandatory ignore `..`.
421
- ( true , true , true ) => {
422
- handler. emit_warn ( CompileWarning {
423
- span : span. clone ( ) ,
424
- warning_content : Warning :: MatchStructPatternMustIgnorePrivateFields {
367
+ handler. emit_err (
368
+ match (
369
+ is_public_struct_access,
370
+ all_public_fields_are_matched,
371
+ only_public_fields_are_matched,
372
+ ) {
373
+ // Public access. Only all public fields are matched. All missing fields are private.
374
+ // -> Emit error for the mandatory ignore `..`.
375
+ ( true , true , true ) => {
376
+ CompileError :: MatchStructPatternMustIgnorePrivateFields {
425
377
private_fields : missing_fields ( false ) ,
426
378
struct_name : struct_decl. call_path . suffix . clone ( ) ,
427
379
struct_decl_span : struct_decl. span ( ) ,
428
380
all_fields_are_private : struct_decl. has_only_private_fields ( ) ,
429
381
span : span. clone ( ) ,
430
- } ,
431
- } ) ;
432
- }
382
+ }
383
+ }
433
384
434
- // Public access. All public fields are matched. Some private fields are matched.
435
- // -> Do not emit error here because it is already covered when reporting private field.
436
- ( true , true , false ) => {
437
- unreachable ! ( "The above if condition eliminates this case." )
438
- }
385
+ // Public access. All public fields are matched. Some private fields are matched.
386
+ // -> Do not emit error here because it is already covered when reporting private field.
387
+ ( true , true , false ) => {
388
+ unreachable ! ( "The above if condition eliminates this case." )
389
+ }
439
390
440
- // Public access. Some or non of the public fields are matched. Some or none of the private fields are matched.
441
- // -> Emit error listing only missing public fields. Recommendation for mandatory use of `..` is already given
442
- // when reporting the inaccessible private field.
443
- // or
444
- // In struct decl module access. We do not distinguish between private and public fields here.
445
- // -> Emit error listing all missing fields.
446
- ( true , false , _) | ( false , _, _) => {
447
- handler. emit_err ( CompileError :: MatchStructPatternMissingFields {
448
- missing_fields : missing_fields ( is_public_struct_access) ,
449
- missing_fields_are_public : is_public_struct_access,
450
- struct_name : struct_decl. call_path . suffix . clone ( ) ,
451
- struct_decl_span : struct_decl. span ( ) ,
452
- total_number_of_fields : struct_decl. fields . len ( ) ,
453
- span : span. clone ( ) ,
454
- } ) ;
455
- }
456
- } ;
391
+ // Public access. Some or non of the public fields are matched. Some or none of the private fields are matched.
392
+ // -> Emit error listing only missing public fields. Recommendation for mandatory use of `..` is already given
393
+ // when reporting the inaccessible private field.
394
+ // or
395
+ // In struct decl module access. We do not distinguish between private and public fields here.
396
+ // -> Emit error listing all missing fields.
397
+ ( true , false , _) | ( false , _, _) => {
398
+ CompileError :: MatchStructPatternMissingFields {
399
+ missing_fields : missing_fields ( is_public_struct_access) ,
400
+ missing_fields_are_public : is_public_struct_access,
401
+ struct_name : struct_decl. call_path . suffix . clone ( ) ,
402
+ struct_decl_span : struct_decl. span ( ) ,
403
+ total_number_of_fields : struct_decl. fields . len ( ) ,
404
+ span : span. clone ( ) ,
405
+ }
406
+ }
407
+ } ,
408
+ ) ;
457
409
}
458
410
}
459
411
0 commit comments