Skip to content

semantics for finding main #14541

Closed
Closed
@sigmundch

Description

@sigmundch

I keep running into this and I wonder if this is something we can address before 1.0. It's small enough that I think it's doable, but big enough to require some decision making/consensus from the language team.

The current semantics of main is a bit different of what I normally expect it to be. This is in part because we wrote these semantics before we had the notion of 'exports'.

Current meaning:
If you run "a.dart", look and see if the library define by 'a.dart' has a 'main' in it's scope (either because it is defined or imported) and run it.

Meaning I expected:
If you run "a.dart", see if 'a' has a visible 'main' method (defined directly by 'a.dart' or exported from it) and run it.

The following examples illustrate the differences:

b.dart:
  library b;
  main() => print('hi');

a1.dart:
  import 'b.dart';

a2.dart:
  export 'b.dart';

dart a1.dart # prints 'hi'
dart a2.dart # Dart_Invoke: did not find top-level function 'main'.

Metadata

Metadata

Assignees

Labels

area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions