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

Consider improving error message for top-level expressions #15535

Open
peter-ahe-google opened this issue Dec 9, 2013 · 1 comment
Open

Consider improving error message for top-level expressions #15535

peter-ahe-google opened this issue Dec 9, 2013 · 1 comment
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@peter-ahe-google
Copy link
Contributor

See the discussion in https://groups.google.com/a/dartlang.org/d/msg/misc/gs6DzCA-mHk/-Gy3TCY5JNYJ.

The user is new to Dart and used to top-level expressions in JavaScript. Tried running this program:

library altapp;

import 'package:logging/logging.dart';

Logger.root.level = Level.ALL;

The problem was lack of main method. The error is:

js.dart:5:1: Error: Can't have modifier 'StringToken(Logger)' here.
Try replacing modifier 'StringToken(Logger)' with 'var', 'final', or a type.
Logger.root.level = Level.ALL;
^^^^^^
js.dart:5:12: Error: Can't have modifier 'SymbolToken(.)' here.
Try replacing modifier 'SymbolToken(.)' with 'var', 'final', or a type.
Logger.root.level = Level.ALL;
           ^
js.dart:1:1: Error: Could not find 'main'.
library altapp;

Error: Compilation failed.

Perhaps dart2js can do better.

@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jul 20, 2019
@srawlins
Copy link
Member

srawlins commented Aug 9, 2019

FWIW, dart2js/cfe now reports eight errors for this code:

class Logger {
  static L1 root = L1();
}

class L1 {
  int level;
}

Logger.root.level = 3;

error: The name 'Logger' is already defined.
error: Functions must have an explicit list of parameters.
error: A function body must be provided.
error: Expected a method, getter, setter or operator declaration.
error: Functions must have an explicit list of parameters.
error: Expected a method, getter, setter or operator declaration.
error: A function body must be provided.
error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

5 participants