dart-sdk/tests/language/mixin_constructor_forwarding/const_constructor_test.dart
Robert Nystrom 7ca5ad46ce Set tests that have mixin errors as 2.19.
Mark tests that contain errors about using a class as a mixin to use
language version 2.19 where that's not an error.

This may not fix all of the tests because it's the language version of
the library where the class is declared that matters, not where the
class is used as a mixin. But most tests have all of their declarations
in the same library, so this should fix most.

Change-Id: I910439ebd2f10f731418dc588b7e4619a0841c16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285923
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2023-03-01 15:03:39 +00:00

83 lines
2.9 KiB
Dart

// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// TODO(51557): Decide if the mixins being applied in this test should be
// "mixin", "mixin class" or the test should be left at 2.19.
// @dart=2.19
import "package:expect/expect.dart";
abstract class Mixin {
// Declares no instance variable.
int get x;
int get m => x;
}
class Base {
final int x;
// Non-const constructors.
Base.c1(this.x);
Base.c2([this.x = 37]);
Base.c3({this.x = 37});
// Non-forwarding generative const constructors.
const Base.c4(this.x);
const Base.c5([this.x = 37]);
const Base.c6({this.x = 37});
// Forwarding generative const constructors.
const Base.c7(int x) : this.c4(x);
const Base.c8([int x = 87]) : this.c4(x);
const Base.c9({int x = 87}) : this.c4(x);
const Base.c10(int x) : this.c5(x);
const Base.c11([int x = 87]) : this.c5(x);
const Base.c12({int x = 87}) : this.c5(x);
const Base.c13(int x) : this.c6(x: x);
const Base.c14([int x = 87]) : this.c6(x: x);
const Base.c15({int x = 87}) : this.c6(x: x);
// Non-generative constructor.
const factory Base() = Base.c5;
}
class Application = Base with Mixin;
main() {
Expect.equals(42, new Application.c1(42).m);
Expect.equals(42, new Application.c2(42).m);
Expect.equals(42, new Application.c3(x: 42).m);
Expect.equals(42, const Application.c4(42).m);
Expect.equals(42, const Application.c5(42).m);
Expect.equals(42, const Application.c6(x: 42).m);
Expect.equals(42, const Application.c7(42).m);
Expect.equals(42, const Application.c8(42).m);
Expect.equals(42, const Application.c9(x: 42).m);
Expect.equals(42, const Application.c10(42).m);
Expect.equals(42, const Application.c11(42).m);
Expect.equals(42, const Application.c12(x: 42).m);
Expect.equals(42, const Application.c13(42).m);
Expect.equals(42, const Application.c14(42).m);
Expect.equals(42, const Application.c15(x: 42).m);
Expect.equals(37, new Application.c2().m); //# issue38304: ok
Expect.equals(37, new Application.c3().m);
Expect.equals(37, const Application.c5().m); //# issue38304: continued
Expect.equals(37, const Application.c6().m);
Expect.equals(87, const Application.c8().m); //# issue38304: continued
Expect.equals(87, const Application.c9().m);
Expect.equals(87, const Application.c11().m); //# issue38304: continued
Expect.equals(87, const Application.c12().m);
Expect.equals(87, const Application.c14().m); //# issue38304: continued
Expect.equals(87, const Application.c15().m);
// Only make forwarders const if original constructor is const.
const Application.c1(0); //# 01: compile-time error
const Application.c2(0); //# 02: compile-time error
const Application.c3(x: 0); //# 03: compile-time error
// Only insert forwarders for generative constructors.
new Application(); //# 04: compile-time error
}