Skip to content

Confusing error with constructors and optional parameters #27754

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
eukreign opened this issue Nov 3, 2016 · 3 comments
Closed

Confusing error with constructors and optional parameters #27754

eukreign opened this issue Nov 3, 2016 · 3 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report

Comments

@eukreign
Copy link
Contributor

eukreign commented Nov 3, 2016

I have the following code:

abstract class Row {}

abstract class TotalRow implements Row {}

class TestRow extends Row {
  TestRow(String first, [String second = ""]) {}
}

class TestTotalRow extends TestRow with TotalRow {
  TestTotalRow(String first, [String second = ""]): super(first, second);
}

https://dartpad.dartlang.org/d03416b40588306be9722f72b55fae2a

It produces a strange analyzer error related to optional parameters in constructor:

This mixin application is invalid because all of the constructors in the base class 'TestRow' have optional parameters.

Is this expected behavior? Is it not possible to forward to a constructor with optional parameters?

@Scorpiion
Copy link

Here is an even simpler code example based on @eukreign code, I tried to figure it out on a Dartpad after being posted on slack:

class MyParent { 
  MyParent(String firstName, [String lastName = ""]) {}
}

class MyMixin { }

class MyChildClass1 extends MyParent {
  MyChildClass1(String firstName, String lastName): super(firstName, lastName);
}

class MyChildClass2 extends MyParent with MyMixin {
  MyChildClass2(String firstName, String lastName): super(firstName, lastName);
}

MyChildClass1 works as expected, MyChildClass2 gets the error.

@eukreign
Copy link
Contributor Author

eukreign commented Nov 3, 2016

Related:
#17610
#15101

@kevmoo kevmoo added the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label Nov 4, 2016
@munificent munificent added the closed-duplicate Closed in favor of an existing report label Dec 13, 2016
@munificent
Copy link
Member

Dupe of #15101.

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). closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

4 participants