mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 11:21:05 +01:00
Stop rejecting `extend adapt` of non-class types such as struct and tuple. These don't actually work just yet because name lookup into struct and tuple types is a special case that doesn't handle adapters, but this gets us a bit closer. This also slightly improves error recovery for name lookup into an invalid scope.
318 lines
13 KiB
Plaintext
318 lines
13 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_adapt_bad_decl.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_adapt_bad_decl.carbon
|
|
|
|
// --- fail_not_type.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class Bad {
|
|
// CHECK:STDERR: fail_not_type.carbon:[[@LINE+7]]:3: error: cannot implicitly convert from `Core.IntLiteral` to `type` [ImplicitAsConversionFailure]
|
|
// CHECK:STDERR: adapt 100;
|
|
// CHECK:STDERR: ^~~~~~~~~~
|
|
// CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:3: note: type `Core.IntLiteral` does not implement interface `ImplicitAs(type)` [MissingImplInMemberAccessNote]
|
|
// CHECK:STDERR: adapt 100;
|
|
// CHECK:STDERR: ^~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
adapt 100;
|
|
}
|
|
|
|
// CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:18: error: name `F` not found [NameNotFound]
|
|
// CHECK:STDERR: fn Use(b: Bad) { b.F(); }
|
|
// CHECK:STDERR: ^~~
|
|
// CHECK:STDERR:
|
|
fn Use(b: Bad) { b.F(); }
|
|
|
|
// --- fail_extend_not_type.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class Bad {
|
|
// CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+7]]:3: error: cannot implicitly convert from `Core.IntLiteral` to `type` [ImplicitAsConversionFailure]
|
|
// CHECK:STDERR: extend adapt 100;
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+4]]:3: note: type `Core.IntLiteral` does not implement interface `ImplicitAs(type)` [MissingImplInMemberAccessNote]
|
|
// CHECK:STDERR: extend adapt 100;
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
extend adapt 100;
|
|
}
|
|
|
|
// No diagnostic here, we don't know what names Bad has.
|
|
fn Use(b: Bad) { b.F(); }
|
|
|
|
// --- fail_repeated.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class MultipleAdapts {
|
|
adapt ();
|
|
// CHECK:STDERR: fail_repeated.carbon:[[@LINE+7]]:3: error: multiple `adapt` declarations in class [AdaptDeclRepeated]
|
|
// CHECK:STDERR: adapt {};
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
// CHECK:STDERR: fail_repeated.carbon:[[@LINE-4]]:3: note: previous `adapt` declaration is here [ClassSpecificDeclPrevious]
|
|
// CHECK:STDERR: adapt ();
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
// CHECK:STDERR:
|
|
adapt {};
|
|
}
|
|
|
|
class MultipleAdaptsSameType {
|
|
adapt ();
|
|
// CHECK:STDERR: fail_repeated.carbon:[[@LINE+7]]:3: error: multiple `adapt` declarations in class [AdaptDeclRepeated]
|
|
// CHECK:STDERR: adapt ();
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
// CHECK:STDERR: fail_repeated.carbon:[[@LINE-4]]:3: note: previous `adapt` declaration is here [ClassSpecificDeclPrevious]
|
|
// CHECK:STDERR: adapt ();
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
// CHECK:STDERR:
|
|
adapt ();
|
|
}
|
|
|
|
// --- fail_bad_scope.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
// CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:1: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
|
|
// CHECK:STDERR: adapt {};
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
// CHECK:STDERR:
|
|
adapt {};
|
|
|
|
interface I {
|
|
// CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:3: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
|
|
// CHECK:STDERR: adapt {};
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
// CHECK:STDERR:
|
|
adapt {};
|
|
}
|
|
|
|
class C {
|
|
interface I {
|
|
// CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+3]]:5: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
|
|
// CHECK:STDERR: adapt {};
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
adapt {};
|
|
}
|
|
}
|
|
|
|
// CHECK:STDOUT: --- fail_not_type.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %Bad: type = class_type @Bad [template]
|
|
// CHECK:STDOUT: %.1: Core.IntLiteral = int_value 100 [template]
|
|
// CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
|
|
// CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
|
|
// CHECK:STDOUT: .ImplicitAs = %import_ref.1
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .Bad = %Bad.decl
|
|
// CHECK:STDOUT: .Use = %Use.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %Bad.decl: type = class_decl @Bad [template = constants.%Bad] {} {}
|
|
// CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {
|
|
// CHECK:STDOUT: %b.patt: %Bad = binding_pattern b
|
|
// CHECK:STDOUT: %b.param_patt: %Bad = value_param_pattern %b.patt, runtime_param0
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %Bad.ref: type = name_ref Bad, file.%Bad.decl [template = constants.%Bad]
|
|
// CHECK:STDOUT: %b.param: %Bad = value_param runtime_param0
|
|
// CHECK:STDOUT: %b: %Bad = bind_name b, %b.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @Bad {
|
|
// CHECK:STDOUT: %.loc12_9: Core.IntLiteral = int_value 100 [template = constants.%.1]
|
|
// CHECK:STDOUT: %.loc12_12: type = converted %.loc12_9, <error> [template = <error>]
|
|
// CHECK:STDOUT: adapt_decl <error>
|
|
// CHECK:STDOUT: %.loc13: <witness> = complete_type_witness <error> [template = <error>]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%Bad
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Use(%b.param_patt: %Bad) {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %b.ref: %Bad = name_ref b, %b
|
|
// CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_extend_not_type.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %Bad: type = class_type @Bad [template]
|
|
// CHECK:STDOUT: %.1: Core.IntLiteral = int_value 100 [template]
|
|
// CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
|
|
// CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
|
|
// CHECK:STDOUT: .ImplicitAs = %import_ref.1
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .Bad = %Bad.decl
|
|
// CHECK:STDOUT: .Use = %Use.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %Bad.decl: type = class_decl @Bad [template = constants.%Bad] {} {}
|
|
// CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {
|
|
// CHECK:STDOUT: %b.patt: %Bad = binding_pattern b
|
|
// CHECK:STDOUT: %b.param_patt: %Bad = value_param_pattern %b.patt, runtime_param0
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %Bad.ref: type = name_ref Bad, file.%Bad.decl [template = constants.%Bad]
|
|
// CHECK:STDOUT: %b.param: %Bad = value_param runtime_param0
|
|
// CHECK:STDOUT: %b: %Bad = bind_name b, %b.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @Bad {
|
|
// CHECK:STDOUT: %.loc12_16: Core.IntLiteral = int_value 100 [template = constants.%.1]
|
|
// CHECK:STDOUT: %.loc12_19: type = converted %.loc12_16, <error> [template = <error>]
|
|
// CHECK:STDOUT: adapt_decl <error>
|
|
// CHECK:STDOUT: %.loc13: <witness> = complete_type_witness <error> [template = <error>]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%Bad
|
|
// CHECK:STDOUT: extend <error>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Use(%b.param_patt: %Bad) {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %b.ref: %Bad = name_ref b, %b
|
|
// CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_repeated.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %MultipleAdapts: type = class_type @MultipleAdapts [template]
|
|
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
|
|
// CHECK:STDOUT: %.1: type = struct_type {} [template]
|
|
// CHECK:STDOUT: %.2: <witness> = complete_type_witness %empty_tuple.type [template]
|
|
// CHECK:STDOUT: %MultipleAdaptsSameType: type = class_type @MultipleAdaptsSameType [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .MultipleAdapts = %MultipleAdapts.decl
|
|
// CHECK:STDOUT: .MultipleAdaptsSameType = %MultipleAdaptsSameType.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %MultipleAdapts.decl: type = class_decl @MultipleAdapts [template = constants.%MultipleAdapts] {} {}
|
|
// CHECK:STDOUT: %MultipleAdaptsSameType.decl: type = class_decl @MultipleAdaptsSameType [template = constants.%MultipleAdaptsSameType] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @MultipleAdapts {
|
|
// CHECK:STDOUT: %.loc5_10: %empty_tuple.type = tuple_literal ()
|
|
// CHECK:STDOUT: %.loc5_11: type = converted %.loc5_10, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
|
|
// CHECK:STDOUT: adapt_decl %empty_tuple.type
|
|
// CHECK:STDOUT: %.loc13: %.1 = struct_literal ()
|
|
// CHECK:STDOUT: %.loc14: <witness> = complete_type_witness %empty_tuple.type [template = constants.%.2]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%MultipleAdapts
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @MultipleAdaptsSameType {
|
|
// CHECK:STDOUT: %.loc17_10: %empty_tuple.type = tuple_literal ()
|
|
// CHECK:STDOUT: %.loc17_11: type = converted %.loc17_10, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
|
|
// CHECK:STDOUT: adapt_decl %empty_tuple.type
|
|
// CHECK:STDOUT: %.loc25: %empty_tuple.type = tuple_literal ()
|
|
// CHECK:STDOUT: %.loc26: <witness> = complete_type_witness %empty_tuple.type [template = constants.%.2]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%MultipleAdaptsSameType
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_bad_scope.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %.1: type = struct_type {} [template]
|
|
// CHECK:STDOUT: %I.type.1: type = facet_type <@I.1> [template]
|
|
// CHECK:STDOUT: %Self.1: %I.type.1 = bind_symbolic_name Self, 0 [symbolic]
|
|
// CHECK:STDOUT: %C: type = class_type @C [template]
|
|
// CHECK:STDOUT: %I.type.2: type = facet_type <@I.2> [template]
|
|
// CHECK:STDOUT: %Self.2: %I.type.2 = bind_symbolic_name Self, 0 [symbolic]
|
|
// CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .I = %I.decl
|
|
// CHECK:STDOUT: .C = %C.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %.loc8: %.1 = struct_literal ()
|
|
// CHECK:STDOUT: %I.decl: type = interface_decl @I.1 [template = constants.%I.type.1] {} {}
|
|
// CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @I.1 {
|
|
// CHECK:STDOUT: %Self: %I.type.1 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.1]
|
|
// CHECK:STDOUT: %.loc15: %.1 = struct_literal ()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @I.2 {
|
|
// CHECK:STDOUT: %Self: %I.type.2 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.2]
|
|
// CHECK:STDOUT: %.loc23: %.1 = struct_literal ()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @C {
|
|
// CHECK:STDOUT: %I.decl: type = interface_decl @I.2 [template = constants.%I.type.2] {} {}
|
|
// CHECK:STDOUT: %.loc25: <witness> = complete_type_witness %.1 [template = constants.%.2]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%C
|
|
// CHECK:STDOUT: .I = %I.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|