mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 11:58:12 +00:00
We previously discarded a `generic` applied to `self`, resulting in silently treating `generic self: Self` as a runtime parameter and producing a weird error on `template self: Self`. Instead of forcibly making all `self` parameters non-runtime, change the *default* for a parameter named `self` to be runtime. This is only a partial fix; more work is required to support `fn F(generic self)` with an omitted type.
41 lines
1.3 KiB
Plaintext
41 lines
1.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
|
|
//
|
|
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/destroy.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/self/generic_self.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/self/generic_self.carbon
|
|
|
|
// --- generic_self.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class Class {
|
|
fn F(unused generic self: Self) {}
|
|
}
|
|
|
|
fn G() {
|
|
({} as Class).F();
|
|
}
|
|
|
|
// --- fail_runtime_arg.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class Class {
|
|
fn F(unused generic self: Self) {}
|
|
}
|
|
|
|
fn G(c: Class) {
|
|
// CHECK:STDERR: fail_runtime_arg.carbon:[[@LINE+7]]:3: error: argument for generic parameter is not a compile-time constant [CompTimeArgumentNotConstant]
|
|
// CHECK:STDERR: c.F();
|
|
// CHECK:STDERR: ^~~~~
|
|
// CHECK:STDERR: fail_runtime_arg.carbon:[[@LINE-7]]:23: note: initializing generic parameter `self` declared here [InitializingGenericParam]
|
|
// CHECK:STDERR: fn F(unused generic self: Self) {}
|
|
// CHECK:STDERR: ^~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
c.F();
|
|
}
|