// Copyright (c) 2014, 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. // Formatting can break multitests, so don't format them. // dart format off // Regression test for issue 14348. class A { const A(); } class B extends A { const B(); } class C { final A a; const C(A this.a); const C.optional([A this.a = const A()]); const C.named({A this.a = const A()}); const C.untyped(this.a); const C.subtyped(B this.a); const factory C.redirecting(B a) = D; } class D extends C { const D(B b) : super(b); } class E { const factory E.redirecting1(int a) = F; const factory E.redirecting2(int a) = F.redirecting; const factory E.redirecting3(double a) = F.redirecting; } class F implements E { final V field; const F(this.field); const factory F.redirecting(V field) = G; } class G implements F { final W field; const G(W field) : this.field = field; } main() { const A a = const B(); const C(a); //# 01: ok const C.optional(a); //# 02: ok const C.named(a: a); //# 03: ok const C.untyped(a); //# 04: ok // Can't infer type argument U for C since a has type A and the argument has // type B, not A. So tries to assign A to B which fails. const C.subtyped(a); //# 05: compile-time error const C.redirecting(a); //# 06: compile-time error const C(a); //# 07: ok const C.optional(a); //# 08: ok const C.named(a: a); //# 09: ok const C.untyped(a); //# 10: ok // These are compile-time errors with NNBD because of the implicit downcasts. const C.subtyped(a); //# 11: compile-time error const C.redirecting(a); //# 12: compile-time error const C(a); //# 13: compile-time error const C.optional(a); //# 14: compile-time error const C.named(a: a); //# 15: compile-time error const C.untyped(a); //# 16: compile-time error const C.subtyped(a); //# 17: compile-time error const C.redirecting(a); //# 18: compile-time error const E.redirecting1(0); //# 19: ok const E.redirecting1(''); //# 20: compile-time error const E.redirecting2(0); //# 21: ok const E.redirecting2(''); //# 22: compile-time error const E.redirecting3(0.0); //# 23: ok const E.redirecting3(''); //# 24: compile-time error }