|
| 1 | +// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | +// |
| 5 | +// SharedOptions=--enable-experiment=super-parameters |
| 6 | + |
| 7 | +// ignore_for_file: experiment_not_enabled |
| 8 | +// @dart=2.17 |
| 9 | + |
| 10 | +import 'dart:developer'; |
| 11 | + |
| 12 | +import 'package:test/test.dart'; |
| 13 | +import 'package:vm_service/vm_service.dart'; |
| 14 | + |
| 15 | +import 'common/service_test_common.dart'; |
| 16 | +import 'common/test_helper.dart'; |
| 17 | + |
| 18 | +class S<T> { |
| 19 | + num? n; |
| 20 | + T? t; |
| 21 | + String constrName; |
| 22 | + S({this.n, this.t}) : constrName = "S"; |
| 23 | + S.named({this.t, this.n}) : constrName = "S.named"; |
| 24 | +} |
| 25 | + |
| 26 | +class C<T> extends S<T> { |
| 27 | + C.constr1(String s, {super.t}); |
| 28 | + C.constr2(int i, String s, {super.n}) : super(); |
| 29 | + C.constr3(int i, String s, {super.n, super.t}) : super.named() { |
| 30 | + debugger(); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +class R<T> { |
| 35 | + final f1; |
| 36 | + var v1; |
| 37 | + num i1; |
| 38 | + T t1; |
| 39 | + R(this.f1, this.v1, this.i1, this.t1); |
| 40 | +} |
| 41 | + |
| 42 | +class B<T> extends R<T> { |
| 43 | + // ignore: no_default_super_constructor |
| 44 | + B(super.f1, super.v1, super.i1, super.t1) { |
| 45 | + debugger(); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +void testMain() { |
| 50 | + debugger(); |
| 51 | + C.constr3(1, 'abc', n: 3.14, t: 42); |
| 52 | + B('a', 3.14, 2.718, 42); |
| 53 | +} |
| 54 | + |
| 55 | +late final String isolateId; |
| 56 | +late final String rootLibId; |
| 57 | + |
| 58 | +createInstance(VmService service, String expr) async { |
| 59 | + return await service.evaluate( |
| 60 | + isolateId, |
| 61 | + rootLibId, |
| 62 | + expr, |
| 63 | + disableBreakpoints: true, |
| 64 | + ); |
| 65 | +} |
| 66 | + |
| 67 | +evaluateGetter(VmService service, String instanceId, String getter) async { |
| 68 | + dynamic result = await service.evaluate(isolateId, instanceId, getter); |
| 69 | + return await service.getObject(isolateId, result.id); |
| 70 | +} |
| 71 | + |
| 72 | +final tests = <IsolateTest>[ |
| 73 | + (VmService service, IsolateRef isolateRef) async { |
| 74 | + // Initialization |
| 75 | + isolateId = isolateRef.id!; |
| 76 | + final isolate = await service.getIsolate(isolateId); |
| 77 | + rootLibId = isolate.rootLib!.id!; |
| 78 | + }, |
| 79 | + (VmService service, _) async { |
| 80 | + dynamic instance = await createInstance(service, 'C.constr1("abc", t: 42)'); |
| 81 | + dynamic result = await evaluateGetter(service, instance.id, 'n'); |
| 82 | + expect(result.valueAsString, 'null'); |
| 83 | + result = await evaluateGetter(service, instance.id, 't'); |
| 84 | + expect(result.valueAsString, '42'); |
| 85 | + result = await evaluateGetter(service, instance.id, 'constrName'); |
| 86 | + expect(result.valueAsString, 'S'); |
| 87 | + result = await service.evaluate(isolateId, instance.id, 'T'); |
| 88 | + expect(result.json['name'], 'int'); |
| 89 | + |
| 90 | + instance = await createInstance(service, 'C.constr1("abc", t: "42")'); |
| 91 | + result = await evaluateGetter(service, instance.id, 'n'); |
| 92 | + expect(result.valueAsString, 'null'); |
| 93 | + result = await evaluateGetter(service, instance.id, 't'); |
| 94 | + expect(result.valueAsString, '42'); |
| 95 | + result = await evaluateGetter(service, instance.id, 'constrName'); |
| 96 | + expect(result.valueAsString, 'S'); |
| 97 | + result = await service.evaluate(isolateId, instance.id, 'T'); |
| 98 | + expect(result.json['name'], 'String'); |
| 99 | + }, |
| 100 | + (VmService service, _) async { |
| 101 | + dynamic instance = await createInstance(service, 'C.constr2(1, "abc", n: 3.14)'); |
| 102 | + dynamic result = await evaluateGetter(service, instance.id, 'n'); |
| 103 | + expect(result.valueAsString, '3.14'); |
| 104 | + result = await evaluateGetter(service, instance.id, 't'); |
| 105 | + expect(result.valueAsString, 'null'); |
| 106 | + result = await evaluateGetter(service, instance.id, 'constrName'); |
| 107 | + expect(result.valueAsString, 'S'); |
| 108 | + result = await service.evaluate(isolateId, instance.id, 'T'); |
| 109 | + expect(result.json['name'], 'dynamic'); |
| 110 | + |
| 111 | + instance = await createInstance(service, 'C.constr2(1, "abc", n: 2)'); |
| 112 | + result = await evaluateGetter(service, instance.id, 'n'); |
| 113 | + expect(result.valueAsString, '2'); |
| 114 | + result = await evaluateGetter(service, instance.id, 't'); |
| 115 | + expect(result.valueAsString, 'null'); |
| 116 | + result = await evaluateGetter(service, instance.id, 'constrName'); |
| 117 | + expect(result.valueAsString, 'S'); |
| 118 | + result = await service.evaluate(isolateId, instance.id, 'T'); |
| 119 | + expect(result.json['name'], 'dynamic'); |
| 120 | + }, |
| 121 | + (VmService service, _) async { |
| 122 | + dynamic instance = await createInstance(service, 'C.constr3(1, "abc", n: 42, t: 3.14)'); |
| 123 | + dynamic result = await evaluateGetter(service, instance.id, 'n'); |
| 124 | + expect(result.valueAsString, '42'); |
| 125 | + result = await evaluateGetter(service, instance.id, 't'); |
| 126 | + expect(result.valueAsString, '3.14'); |
| 127 | + result = await evaluateGetter(service, instance.id, 'constrName'); |
| 128 | + expect(result.valueAsString, 'S.named'); |
| 129 | + result = await service.evaluate(isolateId, instance.id, 'T'); |
| 130 | + expect(result.json['name'], 'double'); |
| 131 | + |
| 132 | + instance = await createInstance(service, 'C.constr3(1, "abc", n: 3.14, t: 42)'); |
| 133 | + result = await evaluateGetter(service, instance.id, 'n'); |
| 134 | + expect(result.valueAsString, '3.14'); |
| 135 | + result = await evaluateGetter(service, instance.id, 't'); |
| 136 | + expect(result.valueAsString, '42'); |
| 137 | + result = await evaluateGetter(service, instance.id, 'constrName'); |
| 138 | + expect(result.valueAsString, 'S.named'); |
| 139 | + result = await service.evaluate(isolateId, instance.id, 'T'); |
| 140 | + expect(result.json['name'], 'int'); |
| 141 | + }, |
| 142 | + (VmService service, _) async { |
| 143 | + dynamic instance = await createInstance(service, 'B(1, 2, 3, 4)'); |
| 144 | + dynamic result = await evaluateGetter(service, instance.id, 'f1'); |
| 145 | + expect(result.valueAsString, '1'); |
| 146 | + result = await evaluateGetter(service, instance.id, 'v1'); |
| 147 | + expect(result.valueAsString, '2'); |
| 148 | + result = await evaluateGetter(service, instance.id, 'i1'); |
| 149 | + expect(result.valueAsString, '3'); |
| 150 | + result = await evaluateGetter(service, instance.id, 't1'); |
| 151 | + expect(result.valueAsString, '4'); |
| 152 | + }, |
| 153 | + resumeIsolate, |
| 154 | + hasStoppedAtBreakpoint, |
| 155 | + (VmService service, _) async { |
| 156 | + dynamic result = await service.evaluateInFrame(isolateId, 0, 'n'); |
| 157 | + expect(result.valueAsString, '3.14'); |
| 158 | + result = await service.evaluateInFrame(isolateId, 0, 't'); |
| 159 | + expect(result.valueAsString, '42'); |
| 160 | + result = await service.evaluateInFrame(isolateId, 0, 'constrName'); |
| 161 | + expect(result.valueAsString, 'S.named'); |
| 162 | + }, |
| 163 | + resumeIsolate, |
| 164 | + hasStoppedAtBreakpoint, |
| 165 | + (VmService service, _) async { |
| 166 | + dynamic result = await service.evaluateInFrame(isolateId, 0, 'f1'); |
| 167 | + expect(result.valueAsString, 'a'); |
| 168 | + result = await service.evaluateInFrame(isolateId, 0, 'v1'); |
| 169 | + expect(result.valueAsString, '3.14'); |
| 170 | + result = await service.evaluateInFrame(isolateId, 0, 'i1'); |
| 171 | + expect(result.valueAsString, '2.718'); |
| 172 | + result = await service.evaluateInFrame(isolateId, 0, 't1'); |
| 173 | + expect(result.valueAsString, '42'); |
| 174 | + } |
| 175 | +]; |
| 176 | + |
| 177 | +main([args = const <String>[]]) => runIsolateTests( |
| 178 | + args, |
| 179 | + tests, |
| 180 | + 'super_constructor_invocation_test.dart', |
| 181 | + testeeConcurrent: testMain, |
| 182 | + experiments: ['super-parameters'], |
| 183 | + ); |
0 commit comments