covariant_templates_test.dart 501 Bytes
Newer Older
Adam Barth's avatar
Adam Barth committed
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter_test/flutter_test.dart';
Adam Barth's avatar
Adam Barth committed
6 7 8 9 10 11 12 13 14 15 16

class X {}

class Y extends X {}

class A<U extends X> {
  U u;
}

void main() {
  test('Assignment through a covariant template throws exception', () {
17
    final A<Y> ay = A<Y>();
18
    final A<X> ayAsAx = ay;
Adam Barth's avatar
Adam Barth committed
19
    expect(() {
20
      ayAsAx.u = X();
21
    }, throwsAssertionError);
Adam Barth's avatar
Adam Barth committed
22 23
  });
}