Files
carbon-lang/toolchain/parse/testdata/operators/precedence_where.carbon
T
Dana JansensandJon Ross-Perkins 4b0e2b03b6 Add the .Self name for the type expression of a compile time binding (#5937)
We add a virtual node (`CompileTimeBindingPatternStart`) as the first
child of `CompileTimeBindingPattern` which holds the identifier
underneath it, so that it is checked just before the type expression of
the `CompileTimeBindingPattern`. When we reach this virtual node during
check, we add `.Self` as a name in the current scope, and when we reach
`CompileTimeBindingPattern` we remove it from scope, which ensures it's
present during only the checking of the type expression for the compile
time pattern.

At the moment the `.Self` has a different type (it's a `TypeType`) than
other `.Self` in the facet type (which are a single `FacetType`), but
the intention is to immediately substitute it out of the facet type
entirely, replacing it with a reference to the compile time binding (a
`BindSymbolicName`) itself. A TODO has been added for this.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-08-12 16:27:07 +00:00

100 lines
7.0 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/parse/testdata/operators/precedence_where.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/operators/precedence_where.carbon
fn PostfixStar(T:! I* where .A* == .B*);
fn Ampersand(U:! J & K where C & D impls E & F);
fn BinaryPlus(V:! L + M where G & H impls N & O);
fn UnaryMinus(W:! -P where -Q impls -R);
// CHECK:STDOUT: - filename: precedence_where.carbon
// CHECK:STDOUT: parse_tree: [
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'PostfixStar'},
// CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'T'},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'I'},
// CHECK:STDOUT: {kind: 'PostfixOperatorStar', text: '*', subtree_size: 2},
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 3},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'A'},
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'PostfixOperatorStar', text: '*', subtree_size: 3},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'B'},
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'PostfixOperatorStar', text: '*', subtree_size: 3},
// CHECK:STDOUT: {kind: 'RequirementEqualEqual', text: '==', subtree_size: 7},
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 11},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 14},
// CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 16},
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 19},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'Ampersand'},
// CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'U'},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'J'},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'K'},
// CHECK:STDOUT: {kind: 'InfixOperatorAmp', text: '&', subtree_size: 3},
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 4},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'C'},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'D'},
// CHECK:STDOUT: {kind: 'InfixOperatorAmp', text: '&', subtree_size: 3},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'E'},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'F'},
// CHECK:STDOUT: {kind: 'InfixOperatorAmp', text: '&', subtree_size: 3},
// CHECK:STDOUT: {kind: 'RequirementImpls', text: 'impls', subtree_size: 7},
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 12},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 15},
// CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 17},
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 20},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'BinaryPlus'},
// CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'V'},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'L'},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'M'},
// CHECK:STDOUT: {kind: 'InfixOperatorPlus', text: '+', subtree_size: 3},
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 4},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'G'},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'H'},
// CHECK:STDOUT: {kind: 'InfixOperatorAmp', text: '&', subtree_size: 3},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'N'},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'O'},
// CHECK:STDOUT: {kind: 'InfixOperatorAmp', text: '&', subtree_size: 3},
// CHECK:STDOUT: {kind: 'RequirementImpls', text: 'impls', subtree_size: 7},
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 12},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 15},
// CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 17},
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 20},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'UnaryMinus'},
// CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'W'},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'P'},
// CHECK:STDOUT: {kind: 'PrefixOperatorMinus', text: '-', subtree_size: 2},
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 3},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Q'},
// CHECK:STDOUT: {kind: 'PrefixOperatorMinus', text: '-', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'R'},
// CHECK:STDOUT: {kind: 'PrefixOperatorMinus', text: '-', subtree_size: 2},
// CHECK:STDOUT: {kind: 'RequirementImpls', text: 'impls', subtree_size: 5},
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 9},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 12},
// CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 14},
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 17},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]