mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Correctly reject interface methods type and ptr.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
15
test/test_suite/any/interface_name_shadow.c3
Normal file
15
test/test_suite/any/interface_name_shadow.c3
Normal 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()
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user