You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds the compile_error and compile_warn comptime functions.
Both are very useful for handling cases where, for example, a certain generic type, or an operating system, is not supported.
$ cat x.v
modulemain$if linux {
$compile_error('Linux is not supported')
}
fnmain() {
}
$ ./v2 run x.v
x.v:4:5: error: Linux isnot supported
2|3|$if linux {
4| $compile_error('Linux is not supported')
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~5| }
6|
Nice work, I like the idea of being able to give compile time errors - what are compile warnings good for, though?
It reminds me a bit of the C/C++ -Wall-type of flags needed to activate or hide warnings when using C-based compilers. Either code compiles else the programmer is doing something wrong that deserves an error - what cases or examples do we have for giving a warning at compile time?
Maybe userland compile warnings should at least result in compile errors with -prod - like they do now in the internal system?
It can be in vlib/v/checker/tests/ - a pair of .vv and .out files, where the .vv file has the example, and the .out file is produced by v vlib/v/checker/tests/compile_error.vv > vlib/v/checker/tests/compile_error.out .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the
compile_errorandcompile_warncomptime functions.Both are very useful for handling cases where, for example, a certain generic type, or an operating system, is not supported.