Skip to content

[CFE] Issue when library and its part define the same variable #54836

Open
@sgrekhov

Description

@sgrekhov

Consider the case when one part is used by two owners

// multiple_owners_part.dart
part of multiple_owners_lib;
final definedInPart = "Lily was here";

// multiple_owners_owner_1.dart
library multiple_owners_lib;
part 'multiple_owners_part.dart';

var definedInPart = "";

main() {
}

// multiple_owners_owner_2.dart
library multiple_owners_lib;
part 'multiple_owners_part.dart';

main() {
  print(definedInPart);
}

Now CFE report the following error for multiple_owners_owner_1.dart

$ out/ReleaseX64/dart tests/co19/src/Language/Libraries_and_Scripts/Parts/multiple_owners_owner_1.dart
tests/co19/src/Language/Libraries_and_Scripts/Parts/multiple_owners_part.dart:7:7: Error: 'definedInPart' is already declared in this scope.
final definedInPart = "Lily was here";
      ^^^^^^^^^^^^^
tests/co19/src/Language/Libraries_and_Scripts/Parts/multiple_owners_owner_1.dart:18:5: Context: Previous declaration of 'definedInPart'.
var definedInPart = "";
    ^^^^^^^^^^^^^

So, CFE reports that the error occurs in part. But if we take a look at multiple_owners_part.dart or at multiple_owners_owner_2.dart we won't see anything wrong in part itself or in another library that use it (multiple_owners_owner_2.dart). So, may be it makes sense to report that error occurs in multiple_owners_owner_1.dart, not in multiple_owners_part.dart?

Metadata

Metadata

Assignees

No one assigned

    Labels

    legacy-area-front-endLegacy: Use area-dart-model instead.model-messagesPoor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE.type-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions