Files
sdk/tests/language/constructor/reference_test.dart
T
Johnni Winther f49d92aba9 [cfe] Use LookupResult for constructor lookup
This adds `LookupResult.isInvalidLookup` to the handle invalid lookup
results and uses this to avoid a lot of cascading error messages.

This is a step towards removing ProblemBuilder, AmbiguousBuilder and
reliance on `NamedBuilder.isDuplicate` in lookups.

Change-Id: Ia9d558ce55b45567607282295dd1e54e6187f9c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441880
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2025-07-29 04:41:21 -07:00

102 lines
3.6 KiB
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.
class Foo<X> {
const Foo();
const Foo.bar();
const Foo.baz();
}
main() {
new Foo();
new Foo.bar();
new Foo.bar.baz();
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE
// [cfe] Couldn't find constructor 'Foo.bar.baz'.
new Foo<int>();
new Foo<int>.bar();
new Foo<int>.bar.baz();
// ^^^
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
// [cfe] Expected '(' after this.
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] The method 'baz' isn't defined for the type 'Foo<int>'.
new Foo.bar<int>();
// ^
// [cfe] A constructor invocation can't have type arguments after the constructor name.
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR
new Foo.bar<int>.baz();
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE
// [cfe] Couldn't find constructor 'Foo.bar.baz'.
new Foo.bar.baz<int>();
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE
// [cfe] Couldn't find constructor 'Foo.bar.baz'.
// ^^^
// [analyzer] SYNTACTIC_ERROR.CONSTRUCTOR_WITH_TYPE_ARGUMENTS
// [cfe] A constructor invocation can't have type arguments after the constructor name.
const Foo();
const Foo.bar();
const Foo.bar.baz();
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE
// [cfe] Couldn't find constructor 'Foo.bar.baz'.
const Foo<int>();
const Foo<int>.bar();
const Foo<int>.bar.baz();
// ^^^
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
// [cfe] Expected '(' after this.
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] The method 'baz' isn't defined for the type 'Foo<int>'.
const Foo.bar<int>();
// ^
// [cfe] A constructor invocation can't have type arguments after the constructor name.
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR
const Foo.bar<int>.baz();
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE
// [cfe] Couldn't find constructor 'Foo.bar.baz'.
const Foo.bar.baz<int>();
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE
// [cfe] Couldn't find constructor 'Foo.bar.baz'.
// ^^^
// [analyzer] SYNTACTIC_ERROR.CONSTRUCTOR_WITH_TYPE_ARGUMENTS
// [cfe] A constructor invocation can't have type arguments after the constructor name.
Foo();
Foo.bar();
Foo.bar.baz();
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] The method 'baz' isn't defined for the type 'Foo<X> Function<X>()'.
Foo<int>();
Foo<int>.bar();
Foo<int>.bar.baz();
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] The method 'baz' isn't defined for the type 'Foo<int> Function()'.
Foo.bar<int>();
// ^
// [cfe] A constructor invocation can't have type arguments after the constructor name.
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR
Foo.bar<int>.baz();
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR
// [cfe] A constructor tear-off can't have type arguments after the constructor name.
Foo.bar.baz<int>();
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] The method 'baz' isn't defined for the type 'Foo<X> Function<X>()'.
}