Skip to content

Commit

Permalink
Don't create a compile time binding after CompileTimeBindingInVarDecl (
Browse files Browse the repository at this point in the history
…#4463)

Related to #4461, more generally try not to produce a compile-time
binding when the code shouldn't be able to do so.
  • Loading branch information
jonmeow authored Oct 31, 2024
1 parent 57c9a2e commit 99e9660
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
2 changes: 2 additions & 0 deletions toolchain/check/handle_binding_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
CompileTimeBindingInVarDecl, Error,
"`var` declaration cannot declare a compile-time binding");
context.emitter().Emit(type_node, CompileTimeBindingInVarDecl);
// Prevent lambda helpers from creating a compile time binding.
needs_compile_time_binding = false;
}
auto binding_id =
is_generic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,10 @@ library "[[@TEST_NAME]]";
// CHECK:STDERR:
var x:! () = ();

// CHECK:STDERR: fail_invalid_file_generic_regression_test.carbon:[[@LINE+4]]:1: error: semantics TODO: `function with positional parameters` [SemanticsTodo]
// CHECK:STDERR: fail_invalid_file_generic_regression_test.carbon:[[@LINE+3]]:1: error: semantics TODO: `function with positional parameters` [SemanticsTodo]
// CHECK:STDERR: fn A {
// CHECK:STDERR: ^~~~~~
// CHECK:STDERR:
fn A {
// CHECK:STDERR: fail_invalid_file_generic_regression_test.carbon:[[@LINE+6]]:3: error: cannot deduce value for generic parameter `x` [DeductionIncomplete]
// CHECK:STDERR: A();
// CHECK:STDERR: ^~
// CHECK:STDERR: fail_invalid_file_generic_regression_test.carbon:[[@LINE-4]]:1: note: while deducing parameters of generic declared here [DeductionGenericHere]
// CHECK:STDERR: fn A {
// CHECK:STDERR: ^~~~~~
A();
}

Expand Down Expand Up @@ -123,7 +116,7 @@ fn A {
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: type = tuple_type () [template]
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, 0 [symbolic]
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x [symbolic]
// CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
// CHECK:STDOUT: %A.type: type = fn_type @A [template]
// CHECK:STDOUT: %A: %A.type = struct_value () [template]
Expand All @@ -137,18 +130,15 @@ fn A {
// CHECK:STDOUT: %.loc8_10.1: %.1 = tuple_literal ()
// CHECK:STDOUT: %.loc8_10.2: type = converted %.loc8_10.1, constants.%.1 [template = constants.%.1]
// CHECK:STDOUT: %x.var: ref %.1 = var x
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, 0, %x.var [symbolic = constants.%x]
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, %x.var [symbolic = constants.%x]
// CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: generic fn @A(file.%x: %.1) {
// CHECK:STDOUT: !definition:
// CHECK:STDOUT:
// CHECK:STDOUT: fn() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A]
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: fn @A() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A]
// CHECK:STDOUT: %A.call: init %.1 = call %A.ref()
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @__global_init() {
Expand All @@ -160,5 +150,3 @@ fn A {
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @A(constants.%x) {}
// CHECK:STDOUT:
4 changes: 2 additions & 2 deletions toolchain/check/testdata/var/no_prelude/fail_generic.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn Main() {
// CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
// CHECK:STDOUT: %.1: type = tuple_type () [template]
// CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, 0 [symbolic]
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x [symbolic]
// CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
Expand All @@ -37,7 +37,7 @@ fn Main() {
// CHECK:STDOUT: %.loc15_12.1: %.1 = tuple_literal ()
// CHECK:STDOUT: %.loc15_12.2: type = converted %.loc15_12.1, constants.%.1 [template = constants.%.1]
// CHECK:STDOUT: %x.var: ref %.1 = var x
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, 0, %x.var [symbolic = constants.%x]
// CHECK:STDOUT: %x: %.1 = bind_symbolic_name x, %x.var [symbolic = constants.%x]
// CHECK:STDOUT: %.loc15_17.1: %.1 = tuple_literal ()
// CHECK:STDOUT: %.loc15_17.2: init %.1 = tuple_init () to %x.var [template = constants.%tuple]
// CHECK:STDOUT: %.loc15_18: init %.1 = converted %.loc15_17.1, %.loc15_17.2 [template = constants.%tuple]
Expand Down

0 comments on commit 99e9660

Please sign in to comment.