Replace impl fn with override fn (#6008)

This proposal renames the syntax used to mark an overriding definition
of a virtual method from `impl fn` to `override fn` to avoid ambiguity:
besides indicating an overriding virtual function, it can be parsed as
an "impl" declaration when the construct following "impl" begins with a
lambda introduced by "fn".

Closes #5711

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Elliott Kalt
2025-09-12 23:27:02 +00:00
committed by GitHub
co-authored by Richard Smith
parent 973d721916
commit f4bd6e42f9
17 changed files with 234 additions and 162 deletions
@@ -22,11 +22,11 @@ fn F() {
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR:
default fn F();
// CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `impl` not allowed; requires class scope [ModifierRequiresClass]
// CHECK:STDERR: impl fn G();
// CHECK:STDERR: ^~~~
// CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `override` not allowed; requires class scope [ModifierRequiresClass]
// CHECK:STDERR: override fn G();
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR:
impl fn G();
override fn G();
// CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `virtual` not allowed; requires class scope [ModifierRequiresClass]
// CHECK:STDERR: virtual fn H();
// CHECK:STDERR: ^~~~~~~