Skip to content

semantics for finding main #14541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sigmundch opened this issue Oct 28, 2013 · 4 comments
Closed

semantics for finding main #14541

sigmundch opened this issue Oct 28, 2013 · 4 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).

Comments

@sigmundch
Copy link
Member

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'.

@gbracha
Copy link
Contributor

gbracha commented Oct 29, 2013

The spec does not actually specify the behavior of main() except for scripts. I suppose it should. The question, I take it, is whether to include main() methods that are exported in addition to locally declared ones and imported ones. I can see the motivation. The existing rules for conflicts hsould ensure that the local main takes precedence, that if the same main is imported multiple times no issue will arise, and that if a true conflict due to multiple mains arise the program will issue warnings and fail dynamically.


Set owner to @gbracha.
Added Accepted label.

@gbracha
Copy link
Contributor

gbracha commented Nov 1, 2013

Fixed in 0.8 spec (revision 29775).


Added Done label.

@kasperl
Copy link

kasperl commented Nov 4, 2013

Filed follow-up bugs:

   dart2js: issue #14762
   vm: issue #14763

Don't know if the analyzer cares about this so CC'ing Brian.


cc @bwilkerson.

@bwilkerson
Copy link
Member

Yes, it does. Thanks.

analyzer: issue #14770

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

6 participants