1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser,checker: support $compile_error('message') and $compile_warn('message') (#14320)

This commit is contained in:
StunxFS
2022-05-09 01:18:26 -04:00
committed by GitHub
parent 4400f9891e
commit d24dce8eb3
6 changed files with 78 additions and 28 deletions

View File

@@ -5433,9 +5433,6 @@ numbers: [1, 2, 3]
3
```
#### `$env`
```v
@@ -5451,6 +5448,34 @@ V can bring in values at compile time from environment variables.
`$env('ENV_VAR')` can also be used in top-level `#flag` and `#include` statements:
`#flag linux -I $env('JAVA_HOME')/include`.
#### `$compile_error` and `$compile_warn`
These two comptime functions are very useful for displaying custom errors/warnings during
compile time.
Both receive as their only argument a string literal that contains the message to display:
```v failcompile nofmt
// x.v
module main
$if linux {
$compile_error('Linux is not supported')
}
fn main() {
}
$ v run x.v
x.v:4:5: error: Linux is not supported
2 |
3 | $if linux {
4 | $compile_error('Linux is not supported')
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 | }
6 |
```
### Environment specific files
If a file has an environment-specific suffix, it will only be compiled for that environment.