// Copyright (c) 2019, 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. // @dart=2.9 class A {} class B extends A {} List xs; List> xss; class Class { void method1a(T t) { if (t is B) { // `t` is now promoted to T & B // The list literal has type List, not List var ys = [t]; xs = ys; } } void method1b(T t) { if (t is B) { // `t` is now promoted to T & B // The list literal has type List>, not List> var yss = [ [t] ]; xss = yss; } } void method2a(T t) { dynamic alias; if (t is B) { // `t` is now promoted to T & B // The list literal has type List, not List var ys = [t]; alias = ys; xs = alias; } } void method2b(T t) { dynamic alias; if (t is B) { // `t` is now promoted to T & B // The list literal has type List>, not List> var yss = [ [t] ]; alias = yss; xss = alias; } } } void main() { throws(() { Class().method2a(B()); print(xs.runtimeType); // 'List'. }); throws(() { Class().method2b(B()); print(xs.runtimeType); // 'List'. }); } void errors() { Class().method1a(B()); Class().method1b(B()); } void throws(void Function() f) { try { f(); } catch (e) { print(e); return; } throw 'Expected throws'; }