xsharp.eu • Report/warning to find potential problems switching to case-sensitive mode
Page 1 of 1

Report/warning to find potential problems switching to case-sensitive mode

Posted: Tue May 24, 2022 9:39 am
by Otto
We have an example where a local variable is called the same as a getter (access) on a class, but only differs in the case of the first letter.

Example:
USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text


FUNCTION Start() AS VOID STRICT
? "Hello World! Today is ",Today()
var myFoo := Foo{}
? myFoo:MyMethod(131)
WAIT
RETURN


CLASS Foo
ACCESS Bar AS INT
RETURN 15

METHOD MyMethod(bar AS INT) AS INT
bar := bar * 2
RETURN Bar

END CLASS

In the case sensitive situation MyMethod returns 15, every time.
In the case insensitive situation MyMethod returns 2x the input of the method, in this case 262.

I'm not aware of a warning in the case-insensitive mode that warns for this.
It would be nice to be able to get a warning for this. Or maybe a report one can run upfront to identify this kind of potential problems.

Report/warning to find potential problems switching to case-sensitive mode

Posted: Tue May 24, 2022 12:53 pm
by VR
One way to "fix" this issue would be to enable the EnforceSelf compile option.

Report/warning to find potential problems switching to case-sensitive mode

Posted: Tue May 24, 2022 12:54 pm
by Otto
That is a good suggestion.