Warnings are a valuable aid for alerting 4D developers to potential code mistakes. With the release of 4D 20 R6, it is now possible to globally define which warnings are generated, enhancing the overall development experience.
Warnings generated by the Compiler and the Live Syntax Checker are crucial for avoiding code errors. They serve as an early alert system, notifying developers of code likely to cause execution errors. This is particularly useful in scenarios such as using pointers, where compilation cannot verify the type of a pointed variable, or dealing with implicit variable type casts.
Tailoring Warnings to Your Project
Depending on the size and complexity of the project, a large number of warnings may be generated. Although these warnings do not prevent compilation, they can sometimes be overwhelming, making it harder for developers to focus on the most critical issues. Recognizing this, many developers have expressed a desire to customize the warning codes generated, and displayed in the Compiler dialog box and code editors.
Introducing Global Warning Definitions
We’ve listened to these developers, and with 4D 20 R6, they can define the warnings they want to be generated globally.
A new tab has been added to the Compiler page of the project Structure Settings dialog box. This tab contains a list of all available warnings. Only warnings checked in the list will be generated globally, in the compiler dialog, and in the code editors (4D code editor and VS Code).
Even if a warning type is generated or not according to the parameters set, it is still possible to activate and deactivate the checking of a warning type locally in the code using the legacy //%W+ and //%W- switches.
By default, all warning types are enabled, reflecting our belief in their value as crucial aids for developers. However, we understand that each project has unique requirements, so you have the power to show or hide specific warnings to suit your needs.
NEW OPTION FOR COMPILE PROJECT COMMAND
The Compile project command returns a list of warnings encountered during compilation. By default, the command takes into account the warnings defined in the Structure Settings, and returns the same list as the one displayed in the Compiler dialog box.
But you can now impact this list using a warnings collection in the options parameter of the command.
Take a look at this code example in which all warnings except #518.1 and #518.2 will be returned in the $warnings collection:
var $options:={warnings: []}
$options.warnings.push({major: 518; minor: 1; enabled: False})
$options.warnings.push({major: 518; minor: 2; enabled: False})
var $result:=Compile project($options)
var $warnings:=$result.errors.query("isError = :1"; False)
Your feedback matters
We strive to provide our users with the best possible experience, and we encourage you to share your thoughts and comments on the 4D forum. Your feedback helps us understand your needs and continually improve our products and services.
Happy coding!