Correctly reject interface methods type and ptr.

This commit is contained in:
Christoffer Lerno
2025-07-01 20:08:46 +02:00
parent 89507bd335
commit ad48637cbb
3 changed files with 22 additions and 1 deletions

View File

@@ -12,6 +12,7 @@
### Fixes
- mkdir/rmdir would not work properly with substring paths on non-windows platforms.
- Hex string formatter check incorrectly rejected slices.
- Correctly reject interface methods `type` and `ptr`.
### Stdlib changes

View File

@@ -923,8 +923,13 @@ static bool sema_analyse_interface(SemaContext *context, Decl *decl, bool *erase
{
RETRY:;
Decl *method = functions[i];
if (method->name == kw_ptr || method->name == kw_type)
{
RETURN_SEMA_ERROR(method, "The method name '%s' would shadow the built-in property '.%s', "
"please select a different name.", method->name, method->name);
}
// The method might have been resolved earlier, if so we either exit or go to the next.
// This might happen for example if it was resolved using $checks
// This might happen for example if it was resolved using $defined
if (method->resolve_status == RESOLVE_DONE)
{
if (!decl_ok(method)) return false;

View File

@@ -0,0 +1,15 @@
import std::io;
interface Abc
{
fn void type(); // #error: would shadow the built-in property '.type'
}
interface Bcd
{
fn void ptr(); // #error: would shadow the built-in property '.ptr'
}
fn void main()
{
}