dart / sdk / 28a8fa50f67b442ea9e17868a16a95f4c9f39204 / . / tests / compiler / dart2js_extra / instantiation_stub_test.dart

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

// dart2jsOptions=--strong | |

import 'package:expect/expect.dart'; | |

// This needs one-arg instantiation. | |

@NoInline() | |

T f1a<T>(T t) => t; | |

// This needs no instantiation because it is not closurized. | |

@NoInline() | |

T f1b<T>(T t1, T t2) => t1; | |

class Class { | |

// This needs two-arg instantiation. | |

@NoInline() | |

bool f2a<T, S>(T t, S s) => t == s; | |

// This needs no instantiation because it is not closurized. | |

@NoInline() | |

bool f2b<T, S>(T t, S s1, S s2) => t == s1; | |

} | |

@NoInline() | |

int method1(int i, int Function(int) f) => f(i); | |

@NoInline() | |

bool method2(int a, int b, bool Function(int, int) f) => f(a, b); | |

@NoInline() | |

int method3(int a, int b, int c, int Function(int, int, int) f) => f(a, b, c); | |

main() { | |

// This needs three-arg instantiation. | |

T local1<T, S, U>(T t, S s, U u) => t; | |

// This needs no instantiation because but a local function is always | |

// closurized so we assume it does. | |

T local2<T, S, U>(T t, S s, U u1, U u2) => t; | |

Expect.equals(42, method1(42, f1a)); | |

Expect.equals(f1b(42, 87), 42); | |

Class c = new Class(); | |

Expect.isFalse(method2(0, 1, c.f2a)); | |

Expect.isFalse(c.f2b(42, 87, 123)); | |

Expect.equals(0, method3(0, 1, 2, local1)); | |

Expect.equals(42, local2(42, 87, 123, 256)); | |

} |