Skip to content

Static methods calls allowed from const constructor initialization list #4294

Closed
@DartBot

Description

@DartBot

This issue was originally filed by @aam


Problem is that following sample(attached) dart compiles without errors:
===
class BankAccount {
    final int balance;

    BankAccount(int this.balance);
    //
    // const constructor initialization should not allow
    // static methods invocation:
    //
    // see http://www.dartlang.org/docs/spec/latest/dart-language-specification.html#h.gk4elj1gohb4
    //
    const BankAccount.withSurprise(): this(BankAccount.draw());
    static int draw() {
        var isLucky = ((new Date.now().millisecond) & 42) == 42;
        return isLucky? 1E9: 1E4;
    }
    String toString() { return "$balance"; }
}

void main() {
    const ba = const BankAccount.withSurprise();
}
===

Dart compiler should have flagged line with const constructor as erroneous since initialization list invokes static method.

This is on https://dart.googlecode.com/svn/branches/bleeding_edge/dart rev 10031. Running dart on Windows.


Attachment:
testconstconstr.dart (569 Bytes)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions