Skip to content

Package imports and relative imports don't resolve to the same type anymore #33887

Closed
@enyo

Description

@enyo
Dart VM version: 2.0.0-dev.69.0 (Tue Jul 17 14:57:16 2018 +0200) on "macos_x64"
macOS mojave

When to different files include the same file, once with import "package:mylib/test.dart"; and once with import "test.dart"; the dart runtime doesn't recognise the classes to be identical anymore.

// lib/test.dart
class Foo {
}

// lib/a.dart
import 'test.dart';
Foo getFoo() => new Foo();

// lib/b.dart
import 'package:mylib/test.dart';
import 'a.dart';

main() {
  Foo foo = getFoo(); // This fails
}

Error:

Error: A value of type '#lib1::Foo' can't be assigned to a variable of type '#lib2::Foo'.
Try changing the type of the left hand side, or casting the right hand side to '#lib2::Foo'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions