Skip to content

Commit 99e9660

Browse files
authored
Don't create a compile time binding after CompileTimeBindingInVarDecl (#4463)
Related to #4461, more generally try not to produce a compile-time binding when the code shouldn't be able to do so.
1 parent 57c9a2e commit 99e9660

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

toolchain/check/handle_binding_pattern.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
9393
CompileTimeBindingInVarDecl, Error,
9494
"`var` declaration cannot declare a compile-time binding");
9595
context.emitter().Emit(type_node, CompileTimeBindingInVarDecl);
96+
// Prevent lambda helpers from creating a compile time binding.
97+
needs_compile_time_binding = false;
9698
}
9799
auto binding_id =
98100
is_generic

toolchain/check/testdata/function/declaration/no_prelude/fail_todo_no_params.carbon

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,10 @@ library "[[@TEST_NAME]]";
5151
// CHECK:STDERR:
5252
var x:! () = ();
5353

54-
// CHECK:STDERR: fail_invalid_file_generic_regression_test.carbon:[[@LINE+4]]:1: error: semantics TODO: `function with positional parameters` [SemanticsTodo]
54+
// CHECK:STDERR: fail_invalid_file_generic_regression_test.carbon:[[@LINE+3]]:1: error: semantics TODO: `function with positional parameters` [SemanticsTodo]
5555
// CHECK:STDERR: fn A {
5656
// CHECK:STDERR: ^~~~~~
57-
// CHECK:STDERR:
5857
fn A {
59-
// CHECK:STDERR: fail_invalid_file_generic_regression_test.carbon:[[@LINE+6]]:3: error: cannot deduce value for generic parameter `x` [DeductionIncomplete]
60-
// CHECK:STDERR: A();
61-
// CHECK:STDERR: ^~
62-
// CHECK:STDERR: fail_invalid_file_generic_regression_test.carbon:[[@LINE-4]]:1: note: while deducing parameters of generic declared here [DeductionGenericHere]
63-
// CHECK:STDERR: fn A {
64-
// CHECK:STDERR: ^~~~~~
6558
A();
6659
}
6760

@@ -123,7 +116,7 @@ fn A {
123116
// CHECK:STDOUT:
124117
// CHECK:STDOUT: constants {
125118
// CHECK:STDOUT: %.1: type = tuple_type () [template]
126-
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, 0 [symbolic]
119+
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x [symbolic]
127120
// CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
128121
// CHECK:STDOUT: %A.type: type = fn_type @A [template]
129122
// CHECK:STDOUT: %A: %A.type = struct_value () [template]
@@ -137,18 +130,15 @@ fn A {
137130
// CHECK:STDOUT: %.loc8_10.1: %.1 = tuple_literal ()
138131
// CHECK:STDOUT: %.loc8_10.2: type = converted %.loc8_10.1, constants.%.1 [template = constants.%.1]
139132
// CHECK:STDOUT: %x.var: ref %.1 = var x
140-
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, 0, %x.var [symbolic = constants.%x]
133+
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, %x.var [symbolic = constants.%x]
141134
// CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
142135
// CHECK:STDOUT: }
143136
// CHECK:STDOUT:
144-
// CHECK:STDOUT: generic fn @A(file.%x: %.1) {
145-
// CHECK:STDOUT: !definition:
146-
// CHECK:STDOUT:
147-
// CHECK:STDOUT: fn() {
148-
// CHECK:STDOUT: !entry:
149-
// CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A]
150-
// CHECK:STDOUT: return
151-
// CHECK:STDOUT: }
137+
// CHECK:STDOUT: fn @A() {
138+
// CHECK:STDOUT: !entry:
139+
// CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A]
140+
// CHECK:STDOUT: %A.call: init %.1 = call %A.ref()
141+
// CHECK:STDOUT: return
152142
// CHECK:STDOUT: }
153143
// CHECK:STDOUT:
154144
// CHECK:STDOUT: fn @__global_init() {
@@ -160,5 +150,3 @@ fn A {
160150
// CHECK:STDOUT: return
161151
// CHECK:STDOUT: }
162152
// CHECK:STDOUT:
163-
// CHECK:STDOUT: specific @A(constants.%x) {}
164-
// CHECK:STDOUT:

toolchain/check/testdata/var/no_prelude/fail_generic.carbon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn Main() {
2121
// CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
2222
// CHECK:STDOUT: %.1: type = tuple_type () [template]
2323
// CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
24-
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, 0 [symbolic]
24+
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x [symbolic]
2525
// CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
2626
// CHECK:STDOUT: }
2727
// CHECK:STDOUT:
@@ -37,7 +37,7 @@ fn Main() {
3737
// CHECK:STDOUT: %.loc15_12.1: %.1 = tuple_literal ()
3838
// CHECK:STDOUT: %.loc15_12.2: type = converted %.loc15_12.1, constants.%.1 [template = constants.%.1]
3939
// CHECK:STDOUT: %x.var: ref %.1 = var x
40-
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, 0, %x.var [symbolic = constants.%x]
40+
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, %x.var [symbolic = constants.%x]
4141
// CHECK:STDOUT: %.loc15_17.1: %.1 = tuple_literal ()
4242
// CHECK:STDOUT: %.loc15_17.2: init %.1 = tuple_init () to %x.var [template = constants.%tuple]
4343
// CHECK:STDOUT: %.loc15_18: init %.1 = converted %.loc15_17.1, %.loc15_17.2 [template = constants.%tuple]

0 commit comments

Comments
 (0)