diff options
| author | Yong He <yonghe@outlook.com> | 2025-06-16 20:37:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-16 20:37:27 -0700 |
| commit | a4345725a083651c16795d27fedd769f2d7e55ae (patch) | |
| tree | 763c27f687e25e081a87cd266ca1442f5f6624ad /tests/diagnostics | |
| parent | 07f79b943c3041dd18137d72893af260b75ddcf9 (diff) | |
Require `override` keyword for overriding default interface methods. (#7458)
* Require `override` keyword for overriding default interface methods.
* Update doc.
* Fix test.
Diffstat (limited to 'tests/diagnostics')
| -rw-r--r-- | tests/diagnostics/missing-override.slang | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/diagnostics/missing-override.slang b/tests/diagnostics/missing-override.slang new file mode 100644 index 000000000..cc2cbcad3 --- /dev/null +++ b/tests/diagnostics/missing-override.slang @@ -0,0 +1,20 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): + +interface IFoo +{ + int getVal() { return 0; } +} + +struct Impl : IFoo +{ + // Missing override for getVal, which should trigger a diagnostic. + // CHECK: ([[# @LINE+1]]): error 30853 + int getVal() { return 1; } +} + +struct Impl2 : IFoo +{ + // Overriding getVal with a different signature should also trigger a diagnostic. + // CHECK: ([[# @LINE+1]]): error 30854 + override int getVal(int x) { return x; } +}
\ No newline at end of file |
