Files
carbon-lang/toolchain/check/testdata/eval/unexpected_runtime.carbon
T
Dana JansensandJon Ross-Perkins f02ad1f1ca Diagnose runtime values in eval where a constant value was expected (#5659)
Uses of `ConstantValueStore::GetConstantInstId` or
`ConstantValueStore::GetInstId` in eval indicate that the code expects a
constant value. Instead of just ending up with `None` in strange places,
diagnose this and convert to an `ErrorInst` when expectations are not
met.

We add `RequireConstantValue` to pair with `GetConstantValue`, and
rename `GetConstantValueIgnoringPeriodSelf` to
`RequireConstantValueIgnoringPeriodSelf` since the former would just be
unused.

Adds a test where a runtime value ends up in the RHS of a rewrite
constraint, where a constant value is expected. This issue was uncovered
by a fuzzer.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-06-13 14:32:54 +00:00

28 lines
1017 B
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
//
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/eval/unexpected_runtime.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/eval/unexpected_runtime.carbon
// --- fail_unexpected_runtime.carbon
var x: type;
interface Z {
let T:! type;
}
class D {
// CHECK:STDERR: fail_unexpected_runtime.carbon:[[@LINE+4]]:31: error: expression is runtime; expected constant [EvalRequiresConstantValue]
// CHECK:STDERR: extend impl as Z where .T = x {}
// CHECK:STDERR: ^
// CHECK:STDERR:
extend impl as Z where .T = x {}
}