mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add parse support for multiple requirements after where separated by and (#4298)
Follow on to #4275 that added `where` parse support. --------- Co-authored-by: Josh L <josh11b@users.noreply.github.com> Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Josh L
Richard Smith
parent
6bfaa888e8
commit
d6b2fb1736
@@ -1,36 +0,0 @@
|
||||
// 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/where_expr/fail_todo_where_and.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/where_expr/fail_todo_where_and.carbon
|
||||
|
||||
// TODO: Support `and` to allow multiple requirements in `where` expressions.
|
||||
|
||||
// CHECK:STDERR: fail_todo_where_and.carbon:[[@LINE+3]]:31: ERROR: Expected `,` or `)`.
|
||||
// CHECK:STDERR: fn Foo(T: type where .U = i32 and .V == .W and .X impls I);
|
||||
// CHECK:STDERR: ^~~
|
||||
fn Foo(T: type where .U = i32 and .V == .W and .X impls I);
|
||||
|
||||
// CHECK:STDOUT: - filename: fail_todo_where_and.carbon
|
||||
// CHECK:STDOUT: parse_tree: [
|
||||
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
|
||||
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'Foo'},
|
||||
// CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'T'},
|
||||
// CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'U'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'RequirementEqual', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 7},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 9},
|
||||
// CHECK:STDOUT: {kind: 'TuplePattern', text: ')', has_error: yes, subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 14},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
// CHECK:STDOUT: ]
|
||||
@@ -0,0 +1,143 @@
|
||||
// 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/where_expr/where_and.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/where_expr/where_and.carbon
|
||||
|
||||
// --- success.carbon
|
||||
|
||||
fn OneAnd(T:! type where .U = i32 and .V == .W);
|
||||
|
||||
fn TwoAnd(Y:! I where .J impls K and .L == .M and .N = bool);
|
||||
|
||||
// --- fail_and_prefix.carbon
|
||||
|
||||
// CHECK:STDERR: fail_and_prefix.carbon:[[@LINE+4]]:29: ERROR: Expected expression.
|
||||
// CHECK:STDERR: fn AndPrefix(T:! type where and .V == .W);
|
||||
// CHECK:STDERR: ^~~
|
||||
// CHECK:STDERR:
|
||||
fn AndPrefix(T:! type where and .V == .W);
|
||||
|
||||
// --- fail_and_suffix.carbon
|
||||
|
||||
// CHECK:STDERR: fail_and_suffix.carbon:[[@LINE+4]]:40: ERROR: Expected expression.
|
||||
// CHECK:STDERR: fn AndSuffix(Y:! I where .J impls K and);
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
fn AndSuffix(Y:! I where .J impls K and);
|
||||
|
||||
// --- fail_and_early.carbon
|
||||
|
||||
// CHECK:STDERR: fail_and_early.carbon:[[@LINE+3]]:28: ERROR: Requirement should use `impls`, `=`, or `==` operator.
|
||||
// CHECK:STDERR: fn AndEarly(Z:! L where .M and N);
|
||||
// CHECK:STDERR: ^~~
|
||||
fn AndEarly(Z:! L where .M and N);
|
||||
|
||||
// CHECK:STDOUT: - filename: success.carbon
|
||||
// CHECK:STDOUT: parse_tree: [
|
||||
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
|
||||
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'OneAnd'},
|
||||
// CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'T'},
|
||||
// CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'U'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'RequirementEqual', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'RequirementAnd', text: 'and'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'V'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'W'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'RequirementEqualEqual', text: '==', subtree_size: 5},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 13},
|
||||
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 15},
|
||||
// CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 17},
|
||||
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 20},
|
||||
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'TwoAnd'},
|
||||
// CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'Y'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'I'},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'J'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'K'},
|
||||
// CHECK:STDOUT: {kind: 'RequirementImpls', text: 'impls', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'RequirementAnd', text: 'and'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'L'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'M'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'RequirementEqualEqual', text: '==', subtree_size: 5},
|
||||
// CHECK:STDOUT: {kind: 'RequirementAnd', text: 'and'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'N'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'BoolTypeLiteral', text: 'bool'},
|
||||
// CHECK:STDOUT: {kind: 'RequirementEqual', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 18},
|
||||
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 20},
|
||||
// CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 22},
|
||||
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 25},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
// CHECK:STDOUT: ]
|
||||
// CHECK:STDOUT: - filename: fail_and_prefix.carbon
|
||||
// CHECK:STDOUT: parse_tree: [
|
||||
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
|
||||
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'AndPrefix'},
|
||||
// CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'T'},
|
||||
// CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: 'and', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', has_error: yes, subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', has_error: yes, subtree_size: 6},
|
||||
// CHECK:STDOUT: {kind: 'TuplePattern', text: ')', has_error: yes, subtree_size: 8},
|
||||
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
// CHECK:STDOUT: ]
|
||||
// CHECK:STDOUT: - filename: fail_and_suffix.carbon
|
||||
// CHECK:STDOUT: parse_tree: [
|
||||
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
|
||||
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'AndSuffix'},
|
||||
// CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'Y'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'I'},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'J'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'K'},
|
||||
// CHECK:STDOUT: {kind: 'RequirementImpls', text: 'impls', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'RequirementAnd', text: 'and'},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: ')', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', has_error: yes, subtree_size: 9},
|
||||
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', has_error: yes, subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'TuplePattern', text: ')', has_error: yes, subtree_size: 13},
|
||||
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 16},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
// CHECK:STDOUT: ]
|
||||
// CHECK:STDOUT: - filename: fail_and_early.carbon
|
||||
// CHECK:STDOUT: parse_tree: [
|
||||
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
|
||||
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'AndEarly'},
|
||||
// CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'Z'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'L'},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'M'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', has_error: yes, subtree_size: 5},
|
||||
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', has_error: yes, subtree_size: 7},
|
||||
// CHECK:STDOUT: {kind: 'TuplePattern', text: ')', has_error: yes, subtree_size: 9},
|
||||
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 12},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
// CHECK:STDOUT: ]
|
||||
Reference in New Issue
Block a user