// Copyright (c) 2022, 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.

// Tests horizontal inference for a variety of types of invocations.

// SharedOptions=--enable-experiment=inference-update-1

import '../static_type_helper.dart';

testFunctionExpressionInvocation() {
  (<T>(T t, void Function(T) f) => t)(0, (x) {
    x.expectStaticType<Exactly<int>>();
  }).expectStaticType<Exactly<int>>();
}

testInstanceCreation() {
  C(0, (x) {
    x.expectStaticType<Exactly<int>>();
  }).expectStaticType<Exactly<C<int>>>();
}

testInstanceMethodInvocation(B b) {
  b.instanceMethod(0, (x) {
    x.expectStaticType<Exactly<int>>();
  }).expectStaticType<Exactly<int>>();
}

testStaticMethodInvocation() {
  B.staticMethod(0, (x) {
    x.expectStaticType<Exactly<int>>();
  }).expectStaticType<Exactly<int>>();
}

testTopLevelFunctionInvocation() {
  topLevelFunction(0, (x) {
    x.expectStaticType<Exactly<int>>();
  }).expectStaticType<Exactly<int>>();
}

testLocalFunctionInvocation() {
  T localFunction<T>(T t, void Function(T) f) => throw '';
  localFunction(0, (x) {
    x.expectStaticType<Exactly<int>>();
  }).expectStaticType<Exactly<int>>();
}

abstract class B {
  T instanceMethod<T>(T t, void Function(T) f);
  static T staticMethod<T>(T t, void Function(T) f) => throw '';
}

T topLevelFunction<T>(T t, void Function(T) f) => throw '';

class C<T> {
  C(T t, void Function(T) f);
}

main() {}

Test horizontal inference for a variety of invocation types.
Test horizontal inference for a variety of invocation types.

Bug: https://github.com/dart-lang/language/issues/731
Change-Id: I2f3db7b3d9ff6f4a8b374b78d0e3b3b921095a69
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241040
Reviewed-by: Konstantin Shcheglov <09e4d7516628963212bf4aace2f97603d2b706e4@google.com>
Commit-Queue: Paul Berry <72d414e3a99fb120308437779d51667bcc0984eb@google.com>
