Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions toolchain/check/handle_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ auto HandleParseNode(Context& context, Parse::ForallId /*node_id*/) -> bool {
return true;
}

auto HandleParseNode(Context& context, Parse::TypeImplAsId node_id) -> bool {
auto HandleParseNode(Context& context, Parse::ImplTypeAsId node_id) -> bool {
auto [self_node, self_id] = context.node_stack().PopExprWithNodeId();
auto self_type_inst_id = ExprAsType(context, self_node, self_id).inst_id;
context.node_stack().Push(node_id, self_type_inst_id);
Expand All @@ -67,7 +67,7 @@ auto HandleParseNode(Context& context, Parse::TypeImplAsId node_id) -> bool {
return true;
}

auto HandleParseNode(Context& context, Parse::DefaultSelfImplAsId node_id)
auto HandleParseNode(Context& context, Parse::ImplDefaultSelfAsId node_id)
-> bool {
auto self_inst_id = SemIR::TypeInstId::None;

Expand Down
30 changes: 30 additions & 0 deletions toolchain/check/handle_require.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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

#include "toolchain/check/context.h"
#include "toolchain/check/handle.h"
#include "toolchain/parse/node_ids.h"

namespace Carbon::Check {

auto HandleParseNode(Context& context, Parse::RequireIntroducerId node_id)
-> bool {
return context.TODO(node_id, "require");
}

auto HandleParseNode(Context& context, Parse::RequireDefaultSelfImplsId node_id)
-> bool {
return context.TODO(node_id, "require");
}

auto HandleParseNode(Context& context, Parse::RequireTypeImplsId node_id)
-> bool {
return context.TODO(node_id, "require");
}

auto HandleParseNode(Context& context, Parse::RequireDeclId node_id) -> bool {
return context.TODO(node_id, "require");
}

} // namespace Carbon::Check
4 changes: 2 additions & 2 deletions toolchain/check/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ static auto ExtendImpl(Context& context, Parse::NodeId extend_node,
const auto& impl = context.impls().Get(impl_id);

if (context.parse_tree().node_kind(self_type_node_id) ==
Parse::NodeKind::TypeImplAs) {
Parse::NodeKind::ImplTypeAs) {
CARBON_DIAGNOSTIC(ExtendImplSelfAs, Error,
"cannot `extend` an `impl` with an explicit self type");
auto diag = context.emitter().Build(extend_node, ExtendImplSelfAs);
Expand All @@ -448,7 +448,7 @@ static auto ExtendImpl(Context& context, Parse::NodeId extend_node,
// The explicit self type is the same as the default self type, so suggest
// removing it and recover as if it were not present.
if (auto self_as =
context.parse_tree_and_subtrees().ExtractAs<Parse::TypeImplAs>(
context.parse_tree_and_subtrees().ExtractAs<Parse::ImplTypeAs>(
self_type_node_id)) {
CARBON_DIAGNOSTIC(ExtendImplSelfAsDefault, Note,
"remove the explicit `Self` type here");
Expand Down
8 changes: 4 additions & 4 deletions toolchain/check/merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,17 +461,17 @@ static auto CheckRedeclParamSyntax(Context& context,
// https://github.com/carbon-language/carbon-lang/blob/trunk/proposals/p3763.md#redeclarations
auto new_node_kind = context.parse_tree().node_kind(new_node_id);
auto prev_node_kind = context.parse_tree().node_kind(prev_node_id);
if (new_node_kind == Parse::NodeKind::DefaultSelfImplAs &&
if (new_node_kind == Parse::NodeKind::ImplDefaultSelfAs &&
prev_node_kind == Parse::NodeKind::SelfTypeNameExpr &&
context.parse_tree().node_kind(prev_iter[1]) ==
Parse::NodeKind::TypeImplAs) {
Parse::NodeKind::ImplTypeAs) {
++prev_iter;
continue;
}
if (prev_node_kind == Parse::NodeKind::DefaultSelfImplAs &&
if (prev_node_kind == Parse::NodeKind::ImplDefaultSelfAs &&
new_node_kind == Parse::NodeKind::SelfTypeNameExpr &&
context.parse_tree().node_kind(new_iter[1]) ==
Parse::NodeKind::TypeImplAs) {
Parse::NodeKind::ImplTypeAs) {
++new_iter;
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions toolchain/check/node_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ class NodeStack {
case Parse::NodeKind::ParenExprStart:
case Parse::NodeKind::PatternListComma:
case Parse::NodeKind::Placeholder:
case Parse::NodeKind::RequireIntroducer:
case Parse::NodeKind::RequireDefaultSelfImpls:
case Parse::NodeKind::RequireTypeImpls:
case Parse::NodeKind::RequirementAnd:
case Parse::NodeKind::RequirementEqual:
case Parse::NodeKind::RequirementEqualEqual:
Expand Down
54 changes: 54 additions & 0 deletions toolchain/check/testdata/facet/require_invalid.carbon
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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
//
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/facet/require_invalid.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/require_invalid.carbon

// --- fail_todo_require_outside_scope.carbon
library "[[@TEST_NAME]]";

interface Y {}

// CHECK:STDERR: fail_todo_require_outside_scope.carbon:[[@LINE+4]]:1: error: semantics TODO: `require` [SemanticsTodo]
// CHECK:STDERR: require impls Y;
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR:
require impls Y;

// --- fail_todo_require_in_class.carbon
library "[[@TEST_NAME]]";

interface Y {}

class C {
// TODO: require is not allowed outside of `interface` or `constraint`.
// CHECK:STDERR: fail_todo_require_in_class.carbon:[[@LINE+4]]:3: error: semantics TODO: `require` [SemanticsTodo]
// CHECK:STDERR: require impls Y;
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR:
require impls Y;
}

// --- fail_require_in_fn.carbon
library "[[@TEST_NAME]]";

interface Y {}

fn F() {
// require is not allowed outside of `interface` or `constraint`.
// CHECK:STDERR: fail_require_in_fn.carbon:[[@LINE+8]]:3: error: expected expression [ExpectedExpr]
// CHECK:STDERR: require impls Y;
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR:
// CHECK:STDERR: fail_require_in_fn.carbon:[[@LINE+4]]:3: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
// CHECK:STDERR: require impls Y;
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR:
require impls Y;
}
Loading
Loading