Skip to content

$compile_error should locate the actual location of the error #24575

Description

@kbkpbot

Describe the bug

Currently , $compile_error() will point to where it is called, not the real location of error.

Reproduction Steps

compile_error.v

module main

fn son[T](val T) {
        $if T !is int {
                $compile_error('son only taken int as input')
        }
}

fn main() {
        son(false)
}
v compile_error.v

Expected Behavior

something like this:

$ v compile_error.v
compile_error.v:5:3: error: son only taken int as input
    9 | fn main() {
   10 |        son(false)
        |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   11 |}

Current Behavior

$ v compile_error.v
compile_error.v:5:3: error: son only taken int as input
    3 | fn son[T](val T) {
    4 |     $if T !is int {
    5 |         $compile_error('son only taken int as input')
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    6 |     }
    7 | }

Possible Solution

No response

Additional Information/Context

Found be PR #24573

V version

V 0.4.10 ed7a8a3.52c7130

Environment details (OS name and version, etc.)

V full version V 0.4.10 ed7a8a3.52c7130
OS linux, Ubuntu 24.04.2 LTS
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
Memory 6.98GB/15.51GB
V executable /media/HD/github/kbkpbot/v/v
V last modified time 2025-05-25 10:51:48
V home dir OK, value: /media/HD/github/kbkpbot/v
VMODULES OK, value: /home/mars/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/mars/v/bug
Git version git version 2.43.0
V git status weekly.2025.17-162-g0f4e12e7
.git/config present true
cc version cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
gcc version gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
clang version Ubuntu clang version 18.1.3 (1ubuntu1)
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.39-0ubuntu8.4) 2.39

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Feature/Enhancement RequestThis issue is made to request a feature or an enhancement to an existing one.Unit: CheckerBugs/feature requests, that are related to the type checker.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions