Dart 2 compilation doesn't allow for graceful error message with bad `main`
- Dominant language
- Dart
- Stars
- 536
- Forks
- 232
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 10
Description
Things like `int main;` or missing `main` used to have nice error messages but now hit somewhat more cryptic compilation errors.
`main` isn't a method:
before: `Top-level hybridMain is not a function.`
now: `Error: A value of type 'dart.core::int' can't be assigned to a variable of type 'dart.core::Function'.`
Missing `main`:
before: `No top-level hybridMain() function defined.`
now: `Error: Getter not found: 'main'.`
https://github.com/dart-lang/test/blob/1e41eeaeab796fe0559997abc944782db4126133/lib/src/runner/hybrid_listener.dart#L45-L53
The non-method one could be fixed by changing the [bootstrap methods](https://github.com/dart-lang/test/blob/1e41eeaeab796fe0559997abc944782db4126133/lib/src/bootstrap/node.dart#L13) from taking a `Function getMain()` to `dynamic getMain()` which lets the type issue surface in the same place it used to. The missing main would be tougher to fix.
Contributor guide
Research direction
Start with lib/src/runner/hybrid_listener.dart around the main-function checks and lib/src/bootstrap/node.dart around the bootstrap methods. Reproduce the reported cases with a non-method or missing main, then compare the current compiler errors with the earlier graceful messages. Done means both invalid-main cases produce clear, intentional errors again.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100