Files
carbon-lang/toolchain/check/testdata/if_expr/nested.carbon
T
Jon Ross-PerkinsandRichard Smith cad4605dad Add imports of enclosing scopes. (#3575)
Namespaces are copied, which means also adding their name to the
underlying instruction. It happened not to be done previously; the name
was only in name lookup.

Since the only import supported right now is the default import,
functionality is limited; in the future I'll need to deal with namespace
vs package conflicts.

Tests of namespace imports are under "namespace" -- I figured this would
be best for scaling as more instructions get support.

This also improves some debugging-related output that I was trying to
use while trying to build the support.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-01-10 17:36:50 +00:00

60 lines
2.3 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
fn F(a: bool, b: bool, c: bool) -> i32 {
return if a then if b then 1 else 2 else if c then 3 else 4;
}
// CHECK:STDOUT: --- nested.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace package, {.F = %F}
// CHECK:STDOUT: %F: <function> = fn_decl @F
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F(%a: bool, %b: bool, %c: bool) -> i32 {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %a.ref: bool = name_ref a, %a
// CHECK:STDOUT: if %a.ref br !if.expr.then.loc8_10 else br !if.expr.else.loc8_10
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then.loc8_10:
// CHECK:STDOUT: %b.ref: bool = name_ref b, %b
// CHECK:STDOUT: if %b.ref br !if.expr.then.loc8_20 else br !if.expr.else.loc8_20
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then.loc8_20:
// CHECK:STDOUT: %.loc8_30: i32 = int_literal 1
// CHECK:STDOUT: br !if.expr.result.loc8_20(%.loc8_30)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else.loc8_20:
// CHECK:STDOUT: %.loc8_37: i32 = int_literal 2
// CHECK:STDOUT: br !if.expr.result.loc8_20(%.loc8_37)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result.loc8_20:
// CHECK:STDOUT: %.loc8_20: i32 = block_arg !if.expr.result.loc8_20
// CHECK:STDOUT: br !if.expr.result.loc8_10(%.loc8_20)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else.loc8_10:
// CHECK:STDOUT: %c.ref: bool = name_ref c, %c
// CHECK:STDOUT: if %c.ref br !if.expr.then.loc8_44 else br !if.expr.else.loc8_44
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then.loc8_44:
// CHECK:STDOUT: %.loc8_54: i32 = int_literal 3
// CHECK:STDOUT: br !if.expr.result.loc8_44(%.loc8_54)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else.loc8_44:
// CHECK:STDOUT: %.loc8_61: i32 = int_literal 4
// CHECK:STDOUT: br !if.expr.result.loc8_44(%.loc8_61)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result.loc8_44:
// CHECK:STDOUT: %.loc8_44: i32 = block_arg !if.expr.result.loc8_44
// CHECK:STDOUT: br !if.expr.result.loc8_10(%.loc8_44)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result.loc8_10:
// CHECK:STDOUT: %.loc8_10: i32 = block_arg !if.expr.result.loc8_10
// CHECK:STDOUT: return %.loc8_10
// CHECK:STDOUT: }
// CHECK:STDOUT: