Skip to content
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

Improve error message for missing Main class #328

Closed
TobiasWrigstad opened this issue Feb 5, 2016 · 8 comments
Closed

Improve error message for missing Main class #328

TobiasWrigstad opened this issue Feb 5, 2016 · 8 comments
Assignees
Labels
Milestone

Comments

@TobiasWrigstad
Copy link
Contributor

The following program

class Test
  def main() : void
    print "Hello, world!"

is erroneous because the class should be named Main, not Test.

Trying to compile this produces a linker error in clang (!):

Undefined symbols for architecture x86_64:
  "__enc__active_Main_type", referenced from:
      _main in shared-da0c3e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This should change into a proper (understandable) error message much further up the stack!

Similarly, a missing main-method should also be caught.

@EliasC
Copy link
Contributor

EliasC commented Feb 5, 2016

This is a duplicate of #286, but since it's higher in the list, I'll close the old one :)

@TobiasWrigstad
Copy link
Contributor Author

Discussion at meeting 2016-05-12

  1. Need to check for multiple main classes too
  2. Must allow compiling library files that don't contain a main class

@EliasC
Copy link
Contributor

EliasC commented May 12, 2016

@TobiasWrigstad, @PhucVH888:

  1. Here we can either disallow multiple main classes or pick the topmost main class. The former method should be the simplest as we otherwise need to restrict what one can do with a Main object (so that an imported module cannot have code that relies on Main having a certain interface).
  2. To some extent we already support this with the -tc flag (which stops compilation right before code generation). A change to add is to turn of the check for a Main class when this flag is active.

One way to get around the problems in 1. would be to have a main function rather than a Main class, but that requires consensus within the group.

@PhucVH888
Copy link
Contributor

@EliasC I have compiled the program with the -v flag. It seems the compilation does not stop before code generation.

I think before getting the consensus about having a main function rather than a Main class in the next meeting, the issue checking multiple main classes and understandable error message can be fixed first.

== Reading file 'test.enc' ==
== Parsing ==
== Expanding modules ==
== Desugaring ==
== Prechecking ==
== Typechecking ==
== Optimizing ==
== Generating code ==
Undefined symbols for architecture x86_64:
  "__enc__active_Main_type", referenced from:
      _main in shared-03368d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
 *** Compilation failed with exit code 1 ***

@EliasC
Copy link
Contributor

EliasC commented May 13, 2016

@PhucVH888: It generates C-code, but does not compile it (which is enough for typechecking modules without a Main)

@TobiasWrigstad
Copy link
Contributor Author

@EliasC

  1. I'd rather throw an error than silently pick another Main class than what the programmer might think. I suggest we go with the Main class with the main function for now. (One nice way to extend this is to also consider type aliases. If there is no class called Main, we check for type aliases of Main. That way, it is possible to have "lots of main classes" and swap them out easily.)
  2. I am not sure I understand what you mean. Are you saying, we can type check classes in isolation with -tc, and since we don't do separate compilation (yet), that's good enough for now? (If that is what you are saying, then I buy it.)

@EliasC
Copy link
Contributor

EliasC commented May 13, 2016

@TobiasWrigstad

I'd rather throw an error than silently pick another Main class than what the programmer might think.

+1

Are you saying, we can type check classes in isolation with -tc

More or less. We can compile a program, but not run clang on the resulting C-code, which for now doesn't give us the "no main" error. When the compiler actually checks for Main, this check should be aware of -tc (or some other option) so that it lets a lack of Main slide.

@TobiasWrigstad
Copy link
Contributor Author

@EliasC
Good. Then let's consider 2. solved modulo picking the right flag (or deciding it is -tc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants