Type safety!
-
In my actual project myVariable may or may not contain a value. So now I have to add an isDefined check.
Yes but this was already the case - you can't call functions with an undefined variable - I've introduced this "limitation" to HiseScript years ago because the times it silently fails is much higher than when you actually want to pass on an undefined value. It was just that the detection logic so far didn't catch these problems when the object that you call it to is dynamic:
// A const object const var MyEffect = Synth.getEffect("My Effect"); // The same object but not accessed through a const var const var MyDynamicEffect = [MyEffect]; // This will throw an error MyEffect.setAttribute(undefined, 12); // Up until now this went through fine, but should also cause an error just like the line above MyDynamicEffect[0].setAttribute(undefined, 12);
then add this to the docs
Done, but it's not in the HISE docs website because I need to rebuild the HTML files when I'm back tomorrow.
-
I'm finding since this change I am getting some fun errors, but the line numbers given are not correct (or at least are not clear).
For example:
-
@d-healey ah good catch, it mistakenly interpreted a function as a JSON object (which is technically correct, but it should identify as Function before). Should be fixed now.
-
@Christoph-Hart Thank you
-
This safety check is pretty aggressive. I'm trying to track down some API call with undefined parameter 0 errors, but HISE isn't being helpful at the moment.
I get an error at a line that doesn't contain code, and if I comment out the ENTIRE script I still get the error
The only way to make it clear the error is to restart HISE.It seems to be circling around addComboBox, and that combo box initializes with a value of 0.0.
edit:
it seems to initialize to 0.0 if "saveInPreset": "0" . Is that by design? -
@Dan-Korneff said in Type safety!:
I get an error at a line that doesn't contain code
I'm seeing this a lot too. However if you look above the Console, on the same line as the Compile button you might get a more helpful message.
ComboBox values start at 1, so that might be the issue.
-
You guys know you can just change a flag in HISE to restore the old compiler strictness?
I really stand by this decision from a language design perspective,
undefined
as function arguments cause more pain than it is useful, but I understand how annoying it is if you just want to pull the latest changes and find your interface completely broken because of a new restriction.Anyways, I've changed the default value here so that old projects load without issues, and you even can deactivate the warning in the Hise preferences (Development -> Warn If Undefined Parameters) if you want to go full on ostrich on your code quality :)
-
@Christoph-Hart nah, I'd rather know that these issues exist and deal with them. Thankful for the feature, annoyed with debugging
-
@Christoph-Hart do we just need to change #define HISE_WARN_UNDEFINED_PARAMETER_CALLS 0 to 1? or is there something else that needs to be changed?
-
@Adam_G pull the latest changes, then this flag is set and prints the warning. If you then want to disable the warning, untick the box in the preferences.
-
@Christoph-Hart getting some errors on compiling
-
@Adam_G I think that means you are low on RAM. Try closing other programs that you are not using when compiling or reduce the number of threads that VS is using during the compilation.
-
@d-healey said in Type safety!:
@Adam_G I think that means you are low on RAM. Try closing other programs that you are not using when compiling or reduce the number of threads that VS is using during the compilation.
- its more likely to mean that the plugin is using too many png's or wav files stored inside the plugin itself - past about 50Mb (if I recall correctly) the compiler runs out of heap space....on Windows only
-
@d-healey doh! you were right. too many other programs open
-
@Adam_G said in Type safety!:
@d-healey doh! you were right. too many other programs open
careful --- re-running the compile when th eissue is the one I pointed at can sometimes run successfully...
-
I'm running into some undefined parameter warnings that I could use a hand with.
I have a function that adds a childPanel to an existing panel. The paint routine is triggering Warning: undefined parameter 0 if the panel hasn't been created yet, or if the childPanel has been removed.inline function addButton(panel) { local button = panel.addChildPanel(); button.set("allowCallbacks", "Clicks & Hover"); button.setPaintRoutine(function(g) { g.setColour(this.data.hover ? Colours.red : Colours.blue); g.fillPath(myPath, [10, 5, 14, 14]); }); }
Is there a better way to do this that won't throw these warnings?
-
inline function addButton(panel) { if (!isDefined(panel)) return; local button = panel.addChildPanel(); button.set("allowCallbacks", "Clicks & Hover"); button.setPaintRoutine(function(g) { g.setColour(this.data.hover ? Colours.red : Colours.blue); g.fillPath(myPath, [10, 5, 14, 14]); }); }
-
@d-healey Perfect! Simple and effective.
Actually, this method still returns errors -
-
@d-healey I've added this to the childPanel functions:
if (!isDefined(panel)) return;
- Run the function that creates the child panel.
- Close the panel.
- Hit F5 to recompile All Scripts.
Then I get Warning: undefined parameter 0
After closer inspection, the warning is pointing to the line that contains fillPath. I can confirm that this path is being defined.It points to all paint routines