blob: 4e19f32f190c609714bf8469a4ecccc3606b071c [file] [log] [blame]
library test;
//
// Problems in library:
//
// pkg/front_end/testcases/runtime_checks_new/contravariant_generic_return_with_compound_assign_implicit_downcast.dart:49:41: Error: A value of type 'num Function(num)' can't be assigned to a variable of type 'int Function(int)'.
// Try changing the type of the left hand side, or casting the right hand side to 'int Function(int)'.
// d.value /*@checkReturn=(num) -> num*/ += 1;
// ^
//
// pkg/front_end/testcases/runtime_checks_new/contravariant_generic_return_with_compound_assign_implicit_downcast.dart:53:43: Error: A value of type 'num Function(num)' can't be assigned to a variable of type 'int Function(int)'.
// Try changing the type of the left hand side, or casting the right hand side to 'int Function(int)'.
// d.value /*@checkReturn=(num) -> num*/ += 1;
// ^
//
import self as self;
import "dart:core" as core;
class C<T extends core::Object = dynamic> extends core::Object {
final field (self::C::T) core::num plusResult;
constructor •((self::C::T) core::num plusResult) self::C<self::C::T>
: self::C::plusResult = plusResult, super core::Object::•()
;
operator +(core::int i) (self::C::T) core::num
return this.{self::C::plusResult};
}
class D extends core::Object {
final field self::C<core::num> getValue;
field (core::int) core::int setValue = null;
constructor •(self::C<core::num> getValue) self::D
: self::D::getValue = getValue, super core::Object::•()
;
get value() self::C<core::num>
return this.{self::D::getValue};
set value((core::int) core::int value) void {
this.{self::D::setValue} = value;
}
}
static method expectTypeError(() void callback) void {
try {
callback.call();
throw "Expected TypeError, did not occur";
}
on core::TypeError catch(no-exception-var) {
}
}
static method expect(core::Object value, core::Object expected) void {
if(!value.{core::Object::==}(expected)) {
throw "Expected ${expected}, got ${value}";
}
}
static method numToInt(core::num n) core::int
return 1;
static method numToNum(core::num n) core::num
return 2;
static method main() void {
self::D d = new self::D::•(new self::C::•<core::num>(self::numToInt));
let final self::D #t1 = d in #t1.{self::D::value} = let final<BottomType> #t2 = invalid-expression "pkg/front_end/testcases/runtime_checks_new/contravariant_generic_return_with_compound_assign_implicit_downcast.dart:49:41: Error: A value of type 'num Function(num)' can't be assigned to a variable of type 'int Function(int)'.
Try changing the type of the left hand side, or casting the right hand side to 'int Function(int)'.
d.value /*@checkReturn=(num) -> num*/ += 1;
^" in (#t1.{self::D::value}.{self::C::+}(1) as{TypeError} (core::num) → core::num) as{TypeError} (core::int) → core::int;
self::expect(d.{self::D::setValue}(0), 1);
d = new self::D::•(new self::C::•<core::num>(self::numToNum));
self::expectTypeError(() → core::Null {
let final self::D #t3 = d in #t3.{self::D::value} = let final<BottomType> #t4 = invalid-expression "pkg/front_end/testcases/runtime_checks_new/contravariant_generic_return_with_compound_assign_implicit_downcast.dart:53:43: Error: A value of type 'num Function(num)' can't be assigned to a variable of type 'int Function(int)'.
Try changing the type of the left hand side, or casting the right hand side to 'int Function(int)'.
d.value /*@checkReturn=(num) -> num*/ += 1;
^" in (#t3.{self::D::value}.{self::C::+}(1) as{TypeError} (core::num) → core::num) as{TypeError} (core::int) → core::int;
});
self::expect(d.{self::D::setValue}, null);
}