haxe
haxe copied to clipboard
Field should be public as requested by interface
I've been wondering about this particular error situation:
interface I {
function f():Void;
}
class C implements I {
public function new() {}
function f() {} // Field f should be public as requested by I
}
function main() {}
In my mind, having "private" fields which we can unlock by assigning a class to an interface is a useful feature, not an error. It doesn't break into the classes personal space because it decides which interfaces to implement itself, which means we're not "hacking" it from the outside. Instead, we would allow passing around different "views" to the same object in the form of interfaces.
I understand that this would be problematic if the actual runtime access was a problem, which could be the case for truly private fields in some situations. But our private, which is actually protected, is generated as public anyway for various reasons.
At first I wanted to propose allowing @:privateAccess on interfaces to explicitly support this, but I struggle to see why this should be disallowed on any interface implementation. Am I missing something?
First thing that comes to mind is externs which could have "real private" impl? But if that's an issue, disabling this for externs should be an easy enough fix..