Skip to content

Commit 1c09de9

Browse files
authored
Add min_prelude/convert.carbon to tests missing ImplicitAs (#5677)
import_use_generic.carbon has the comment "// We're just checking that this doesn't crash. It's not expected to compile." Because it involves import behavior by name, I'm not touching it. Other than that, while maybe it's better to test with less, the `ImplicitAs` errors at best feel difficult to understand, and at worst could be masking an issue.
1 parent c9e4761 commit 1c09de9

File tree

8 files changed

+165
-48
lines changed

8 files changed

+165
-48
lines changed

toolchain/check/testdata/array/basics.carbon

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Exceptions. See /LICENSE for license information.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
//
5-
// EXTRA-ARGS: --no-prelude-import
5+
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
66
//
77
// AUTOUPDATE
88
// TIP: To test this file alone, run:
@@ -96,7 +96,10 @@ var p: Incomplete* = &a[0];
9696

9797
library "[[@TEST_NAME]]";
9898

99-
// CHECK:STDERR: fail_invalid_element.carbon:[[@LINE+4]]:14: error: `Core.ImplicitAs` implicitly referenced here, but package `Core` not found [CoreNotFound]
99+
// CHECK:STDERR: fail_invalid_element.carbon:[[@LINE+7]]:14: error: cannot implicitly convert non-type value of type `Core.IntLiteral` to `type` [ConversionFailureNonTypeToFacet]
100+
// CHECK:STDERR: var a: array(1, 1);
101+
// CHECK:STDERR: ^
102+
// CHECK:STDERR: fail_invalid_element.carbon:[[@LINE+4]]:14: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
100103
// CHECK:STDERR: var a: array(1, 1);
101104
// CHECK:STDERR: ^
102105
// CHECK:STDERR:
@@ -120,6 +123,9 @@ var a: array(1, 1);
120123
// CHECK:STDOUT: %array: %array_type = tuple_value (%empty_tuple, %empty_tuple, %empty_tuple) [concrete]
121124
// CHECK:STDOUT: }
122125
// CHECK:STDOUT:
126+
// CHECK:STDOUT: imports {
127+
// CHECK:STDOUT: }
128+
// CHECK:STDOUT:
123129
// CHECK:STDOUT: file {
124130
// CHECK:STDOUT: name_binding_decl {
125131
// CHECK:STDOUT: %b.patt: %pattern_type.035 = binding_pattern b [concrete]
@@ -175,6 +181,9 @@ var a: array(1, 1);
175181
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
176182
// CHECK:STDOUT: }
177183
// CHECK:STDOUT:
184+
// CHECK:STDOUT: imports {
185+
// CHECK:STDOUT: }
186+
// CHECK:STDOUT:
178187
// CHECK:STDOUT: fn @G() {
179188
// CHECK:STDOUT: !entry:
180189
// CHECK:STDOUT: name_binding_decl {
@@ -222,6 +231,9 @@ var a: array(1, 1);
222231
// CHECK:STDOUT: %pattern_type.8c1: type = pattern_type %tuple.type [concrete]
223232
// CHECK:STDOUT: }
224233
// CHECK:STDOUT:
234+
// CHECK:STDOUT: imports {
235+
// CHECK:STDOUT: }
236+
// CHECK:STDOUT:
225237
// CHECK:STDOUT: fn @G() {
226238
// CHECK:STDOUT: !entry:
227239
// CHECK:STDOUT: name_binding_decl {
@@ -270,6 +282,9 @@ var a: array(1, 1);
270282
// CHECK:STDOUT: %array: %array_type = tuple_value (%empty_tuple) [concrete]
271283
// CHECK:STDOUT: }
272284
// CHECK:STDOUT:
285+
// CHECK:STDOUT: imports {
286+
// CHECK:STDOUT: }
287+
// CHECK:STDOUT:
273288
// CHECK:STDOUT: fn @Run() {
274289
// CHECK:STDOUT: !entry:
275290
// CHECK:STDOUT: name_binding_decl {
@@ -329,6 +344,9 @@ var a: array(1, 1);
329344
// CHECK:STDOUT: %array: %array_type = tuple_value (%empty_tuple, %empty_tuple, %empty_tuple, %empty_tuple, %empty_tuple, %empty_tuple, %empty_tuple, %empty_tuple, %empty_tuple) [concrete]
330345
// CHECK:STDOUT: }
331346
// CHECK:STDOUT:
347+
// CHECK:STDOUT: imports {
348+
// CHECK:STDOUT: }
349+
// CHECK:STDOUT:
332350
// CHECK:STDOUT: file {
333351
// CHECK:STDOUT: name_binding_decl {
334352
// CHECK:STDOUT: %b.patt: %pattern_type.3db = binding_pattern b [concrete]

toolchain/check/testdata/array/element_mismatches.carbon

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Exceptions. See /LICENSE for license information.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
//
5-
// EXTRA-ARGS: --no-prelude-import
5+
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
66
//
77
// AUTOUPDATE
88
// TIP: To test this file alone, run:
@@ -16,7 +16,10 @@ library "[[@TEST_NAME]]";
1616

1717
class C {}
1818

19-
// CHECK:STDERR: fail_arg_wrong_type.carbon:[[@LINE+4]]:22: error: `Core.ImplicitAs` implicitly referenced here, but package `Core` not found [CoreNotFound]
19+
// CHECK:STDERR: fail_arg_wrong_type.carbon:[[@LINE+7]]:22: error: cannot implicitly convert expression of type `String` to `C` [ConversionFailure]
20+
// CHECK:STDERR: var a: array(C, 3) = ({}, "Hello", "World");
21+
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
22+
// CHECK:STDERR: fail_arg_wrong_type.carbon:[[@LINE+4]]:22: note: type `String` does not implement interface `Core.ImplicitAs(C)` [MissingImplInMemberAccessNote]
2023
// CHECK:STDERR: var a: array(C, 3) = ({}, "Hello", "World");
2124
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
2225
// CHECK:STDERR:

toolchain/check/testdata/function/generic/fail_type_param_mismatch.carbon

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
66
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
7-
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/destroy.carbon
7+
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
88
//
99
// AUTOUPDATE
1010
// TIP: To test this file alone, run:
@@ -14,7 +14,10 @@
1414

1515
fn F(T:! type, U:! type) {
1616
var p: T*;
17-
// CHECK:STDERR: fail_type_param_mismatch.carbon:[[@LINE+4]]:14: error: name `Core.ImplicitAs` implicitly referenced here, but not found [CoreNameNotFound]
17+
// CHECK:STDERR: fail_type_param_mismatch.carbon:[[@LINE+7]]:14: error: cannot implicitly convert expression of type `T` to `U` [ConversionFailure]
18+
// CHECK:STDERR: let n: U = *p;
19+
// CHECK:STDERR: ^~
20+
// CHECK:STDERR: fail_type_param_mismatch.carbon:[[@LINE+4]]:14: note: type `T` does not implement interface `Core.ImplicitAs(U)` [MissingImplInMemberAccessNote]
1821
// CHECK:STDERR: let n: U = *p;
1922
// CHECK:STDERR: ^~
2023
// CHECK:STDERR:
@@ -34,13 +37,29 @@ fn F(T:! type, U:! type) {
3437
// CHECK:STDOUT: %pattern_type.afe: type = pattern_type %ptr [symbolic]
3538
// CHECK:STDOUT: %require_complete.b54: <witness> = require_complete_type %U [symbolic]
3639
// CHECK:STDOUT: %pattern_type.a32: type = pattern_type %U [symbolic]
40+
// CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
41+
// CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
42+
// CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic]
43+
// CHECK:STDOUT: %Convert.type.275: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
44+
// CHECK:STDOUT: %Convert.42e: %Convert.type.275 = struct_value () [symbolic]
45+
// CHECK:STDOUT: %ImplicitAs.assoc_type.ca0: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
46+
// CHECK:STDOUT: %ImplicitAs.type.d88: type = facet_type <@ImplicitAs, @ImplicitAs(%U)> [symbolic]
47+
// CHECK:STDOUT: %ImplicitAs.assoc_type.5fe: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%U) [symbolic]
48+
// CHECK:STDOUT: %assoc0.a0b: %ImplicitAs.assoc_type.5fe = assoc_entity element0, imports.%Core.import_ref.1c7 [symbolic]
49+
// CHECK:STDOUT: %require_complete.6c8: <witness> = require_complete_type %ImplicitAs.type.d88 [symbolic]
50+
// CHECK:STDOUT: %assoc0.dc0: %ImplicitAs.assoc_type.ca0 = assoc_entity element0, imports.%Core.import_ref.207 [symbolic]
3751
// CHECK:STDOUT: }
3852
// CHECK:STDOUT:
3953
// CHECK:STDOUT: imports {
4054
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
41-
// CHECK:STDOUT: .ImplicitAs = <poisoned>
55+
// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
4256
// CHECK:STDOUT: import Core//prelude
57+
// CHECK:STDOUT: import Core//prelude/...
4358
// CHECK:STDOUT: }
59+
// CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
60+
// CHECK:STDOUT: %Core.import_ref.492: @ImplicitAs.%ImplicitAs.assoc_type (%ImplicitAs.assoc_type.ca0) = import_ref Core//prelude/parts/as, loc10_35, loaded [symbolic = @ImplicitAs.%assoc0 (constants.%assoc0.dc0)]
61+
// CHECK:STDOUT: %Core.import_ref.1c7: @ImplicitAs.%Convert.type (%Convert.type.275) = import_ref Core//prelude/parts/as, loc10_35, loaded [symbolic = @ImplicitAs.%Convert (constants.%Convert.42e)]
62+
// CHECK:STDOUT: %Core.import_ref.207 = import_ref Core//prelude/parts/as, loc10_35, unloaded
4463
// CHECK:STDOUT: }
4564
// CHECK:STDOUT:
4665
// CHECK:STDOUT: file {
@@ -66,8 +85,12 @@ fn F(T:! type, U:! type) {
6685
// CHECK:STDOUT: %ptr.loc16_11.2: type = ptr_type %T.loc15_6.2 [symbolic = %ptr.loc16_11.2 (constants.%ptr)]
6786
// CHECK:STDOUT: %require_complete.loc16: <witness> = require_complete_type %ptr.loc16_11.2 [symbolic = %require_complete.loc16 (constants.%require_complete.6e5)]
6887
// CHECK:STDOUT: %pattern_type.loc16: type = pattern_type %ptr.loc16_11.2 [symbolic = %pattern_type.loc16 (constants.%pattern_type.afe)]
69-
// CHECK:STDOUT: %require_complete.loc21: <witness> = require_complete_type %U.loc15_16.2 [symbolic = %require_complete.loc21 (constants.%require_complete.b54)]
70-
// CHECK:STDOUT: %pattern_type.loc21: type = pattern_type %U.loc15_16.2 [symbolic = %pattern_type.loc21 (constants.%pattern_type.a32)]
88+
// CHECK:STDOUT: %require_complete.loc24_10: <witness> = require_complete_type %U.loc15_16.2 [symbolic = %require_complete.loc24_10 (constants.%require_complete.b54)]
89+
// CHECK:STDOUT: %pattern_type.loc24: type = pattern_type %U.loc15_16.2 [symbolic = %pattern_type.loc24 (constants.%pattern_type.a32)]
90+
// CHECK:STDOUT: %ImplicitAs.type.loc24_14.2: type = facet_type <@ImplicitAs, @ImplicitAs(%U.loc15_16.2)> [symbolic = %ImplicitAs.type.loc24_14.2 (constants.%ImplicitAs.type.d88)]
91+
// CHECK:STDOUT: %require_complete.loc24_14: <witness> = require_complete_type %ImplicitAs.type.loc24_14.2 [symbolic = %require_complete.loc24_14 (constants.%require_complete.6c8)]
92+
// CHECK:STDOUT: %ImplicitAs.assoc_type: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%U.loc15_16.2) [symbolic = %ImplicitAs.assoc_type (constants.%ImplicitAs.assoc_type.5fe)]
93+
// CHECK:STDOUT: %assoc0: @F.%ImplicitAs.assoc_type (%ImplicitAs.assoc_type.5fe) = assoc_entity element0, imports.%Core.import_ref.1c7 [symbolic = %assoc0 (constants.%assoc0.a0b)]
7194
// CHECK:STDOUT:
7295
// CHECK:STDOUT: fn() {
7396
// CHECK:STDOUT: !entry:
@@ -82,13 +105,16 @@ fn F(T:! type, U:! type) {
82105
// CHECK:STDOUT: }
83106
// CHECK:STDOUT: %p: ref @F.%ptr.loc16_11.2 (%ptr) = bind_name p, %p.var
84107
// CHECK:STDOUT: name_binding_decl {
85-
// CHECK:STDOUT: %n.patt: @F.%pattern_type.loc21 (%pattern_type.a32) = binding_pattern n [concrete]
108+
// CHECK:STDOUT: %n.patt: @F.%pattern_type.loc24 (%pattern_type.a32) = binding_pattern n [concrete]
86109
// CHECK:STDOUT: }
87110
// CHECK:STDOUT: %p.ref: ref @F.%ptr.loc16_11.2 (%ptr) = name_ref p, %p
88-
// CHECK:STDOUT: %.loc21_15: @F.%ptr.loc16_11.2 (%ptr) = bind_value %p.ref
89-
// CHECK:STDOUT: %.loc21_14.1: ref @F.%T.loc15_6.2 (%T) = deref %.loc21_15
111+
// CHECK:STDOUT: %.loc24_15: @F.%ptr.loc16_11.2 (%ptr) = bind_value %p.ref
112+
// CHECK:STDOUT: %.loc24_14.1: ref @F.%T.loc15_6.2 (%T) = deref %.loc24_15
90113
// CHECK:STDOUT: %U.ref: type = name_ref U, %U.loc15_16.1 [symbolic = %U.loc15_16.2 (constants.%U)]
91-
// CHECK:STDOUT: %.loc21_14.2: @F.%U.loc15_16.2 (%U) = converted %.loc21_14.1, <error> [concrete = <error>]
114+
// CHECK:STDOUT: %ImplicitAs.type.loc24_14.1: type = facet_type <@ImplicitAs, @ImplicitAs(constants.%U)> [symbolic = %ImplicitAs.type.loc24_14.2 (constants.%ImplicitAs.type.d88)]
115+
// CHECK:STDOUT: %.loc24_14.2: @F.%ImplicitAs.assoc_type (%ImplicitAs.assoc_type.5fe) = specific_constant imports.%Core.import_ref.492, @ImplicitAs(constants.%U) [symbolic = %assoc0 (constants.%assoc0.a0b)]
116+
// CHECK:STDOUT: %Convert.ref: @F.%ImplicitAs.assoc_type (%ImplicitAs.assoc_type.5fe) = name_ref Convert, %.loc24_14.2 [symbolic = %assoc0 (constants.%assoc0.a0b)]
117+
// CHECK:STDOUT: %.loc24_14.3: @F.%U.loc15_16.2 (%U) = converted %.loc24_14.1, <error> [concrete = <error>]
92118
// CHECK:STDOUT: %n: @F.%U.loc15_16.2 (%U) = bind_name n, <error> [concrete = <error>]
93119
// CHECK:STDOUT: return
94120
// CHECK:STDOUT: }

toolchain/check/testdata/impl/fail_impl_bad_type.carbon

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
//
55
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
6-
// EXTRA-ARGS: --no-prelude-import --dump-sem-ir-ranges=if-present
6+
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
7+
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
78
//
89
// AUTOUPDATE
910
// TIP: To test this file alone, run:
@@ -13,7 +14,10 @@
1314

1415
interface I {}
1516

16-
// CHECK:STDERR: fail_impl_bad_type.carbon:[[@LINE+4]]:6: error: `Core.ImplicitAs` implicitly referenced here, but package `Core` not found [CoreNotFound]
17+
// CHECK:STDERR: fail_impl_bad_type.carbon:[[@LINE+7]]:6: error: cannot implicitly convert non-type value of type `bool` to `type` [ConversionFailureNonTypeToFacet]
18+
// CHECK:STDERR: impl true as I {}
19+
// CHECK:STDERR: ^~~~
20+
// CHECK:STDERR: fail_impl_bad_type.carbon:[[@LINE+4]]:6: note: type `bool` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
1721
// CHECK:STDERR: impl true as I {}
1822
// CHECK:STDERR: ^~~~
1923
// CHECK:STDERR:
@@ -23,24 +27,37 @@ impl true as I {}
2327
// CHECK:STDOUT:
2428
// CHECK:STDOUT: constants {
2529
// CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
26-
// CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
30+
// CHECK:STDOUT: %Self.826: %I.type = bind_symbolic_name Self, 0 [symbolic]
2731
// CHECK:STDOUT: %true: bool = bool_literal true [concrete]
32+
// CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
33+
// CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
34+
// CHECK:STDOUT: }
35+
// CHECK:STDOUT:
36+
// CHECK:STDOUT: imports {
37+
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
38+
// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
39+
// CHECK:STDOUT: import Core//prelude
40+
// CHECK:STDOUT: import Core//prelude/...
41+
// CHECK:STDOUT: }
42+
// CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
2843
// CHECK:STDOUT: }
2944
// CHECK:STDOUT:
3045
// CHECK:STDOUT: file {
3146
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
47+
// CHECK:STDOUT: .Core = imports.%Core
3248
// CHECK:STDOUT: .I = %I.decl
3349
// CHECK:STDOUT: }
50+
// CHECK:STDOUT: %Core.import = import Core
3451
// CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
3552
// CHECK:STDOUT: impl_decl @impl [concrete] {} {
3653
// CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
37-
// CHECK:STDOUT: %.loc20: type = converted %true, <error> [concrete = <error>]
54+
// CHECK:STDOUT: %.loc24: type = converted %true, <error> [concrete = <error>]
3855
// CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
3956
// CHECK:STDOUT: }
4057
// CHECK:STDOUT: }
4158
// CHECK:STDOUT:
4259
// CHECK:STDOUT: interface @I {
43-
// CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
60+
// CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self.826]
4461
// CHECK:STDOUT:
4562
// CHECK:STDOUT: !members:
4663
// CHECK:STDOUT: .Self = %Self

0 commit comments

Comments
 (0)