I’ve tested this in Mercury and Oxygen, using Fire.
This is the example (Mercury) code I used:
Module Program
Sub Main(args as String())
Dim test As New TestClass
test.test1 = "456"
Console.WriteLine(test.test1)
End Sub
Public Class TestClass
Private test1 As String
Public test2 As String
End Class
End Module
This shouldn’t be working, but it does. The code is working and the output shows “456”. I only get a warning saying “Did you mean test2?”.
In VS this would result in an expected error. What am I missing here?
I believe VB uses a lighter visibility model, where “Private” is visible in the entire file. @Theo69, is that correct?
That said, this case in particular one is further complicated by the fact that TestClass is a nested class inside the program class (modules are static classes); that might affect this, too…
Can I see a full testcase for this? I cannot reproduce that:
namespace ClassLibrary24;
type
Class1 = public class
private
fFoo: String;
protected
public
end;
Class2 = public class
private
protected
public
method x;
begin
var c := new Class1;
c.fFoo := "Test"; // E470 member "fFoo" on type "Class1" cannot be called because it is private
end;
end;
end.
I can’t reproduce it either now. I made a test in Oxygen after I found the problem in Mercury. Sadly, I don’t have that test project anymore. I’m sure I’m did something wrong/stupid. It was late.
So for now the problem seems to be only in Mercury (.NET Core).