diff --git a/releasenotes.md b/releasenotes.md index ff4de6109..da040f434 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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 diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index d113db52d..e4388bb04 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -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; diff --git a/test/test_suite/any/interface_name_shadow.c3 b/test/test_suite/any/interface_name_shadow.c3 new file mode 100644 index 000000000..7dab7cd59 --- /dev/null +++ b/test/test_suite/any/interface_name_shadow.c3 @@ -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() +{ +}