Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder error trying to assign tuple through if in compile-time code #18566

Open
remdragon opened this issue Jun 26, 2023 · 1 comment · May be fixed by #19443
Open

builder error trying to assign tuple through if in compile-time code #18566

remdragon opened this issue Jun 26, 2023 · 1 comment · May be fixed by #19443
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor.

Comments

@remdragon
Copy link

Describe the bug

Getting "This is a compiler bug, please report it" from the following code:

struct App{}

fn ( app &App ) myfunc4() {
	println( 'myfunc4' )
}

fn make[T]( app &T ) {
	$for method in T.methods {
		mut attmap := map[string]string
		for attr in method.attrs {
			key, val := if attr.contains( ':' ) {
				attr.split_once( ':' )
			} else {
				attr, ''
			}
			attmap[key] = val.trim_left( ' ' )
		}
		println( attmap )
	}
}

fn main() {
	mut app := App{}
	make( app )
}

Expected Behavior

It should work the same way it does when not compile time.

Current Behavior

D:/temp/v_0/iffy.4792796928068636788.tmp.c:501: warning: WINVER redefined
D:/temp/v_0/../../../../../..C:\cvs\v\vlib\builtin\builtin.c.v:68: warning: implicit declaration of function 'tcc_backtrace'
D:/temp/v_0/../../../../../..C:\cvs\v\vlib\builtin\builtin_windows.c.v:288: warning: assignment from incompatible pointer type
D:/temp/v_0/../../../../../..C:\cvs\v\vlib\builtin\builtin_windows.c.v:288: warning: assignment makes pointer from integer without a cast
D:/temp/v_0/../../../../../..C:\cvs\v\vlib\builtin\builtin_windows.c.v:288: warning: cast between pointer and integer of different size
D:/temp/v_0/../../../../../..D:\Dropbox\cvs\gravscriptv\iffy.v:17: error: declaration of an array of incomplete type elements
builder error:
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

Reproduction Steps

v run iffy.v

Possible Solution

No response

Additional Information/Context

split_once() default behavior of returning 2 empty strings if the separator doesn't exist isn't useful behavior to me here, so I'm using the if to override the behavior. When reducing the code to a minimal reproducable example, the error went away when I eliminated the compile-time loop.

V version

V 0.3.4 dd24e8a

Environment details (OS name and version, etc.)

V full version: V 0.3.4 dd24e8a
OS: windows, Microsoft Windows 10 Pro v19044 64-bit
Processor: 16 cpus, 64bit, little endian,

getwd: D:\Dropbox\cvs\gravscriptv
vexe: C:\cvs\v\v.exe
vexe mtime: 2023-06-26 05:17:13

vroot: OK, value: C:\cvs\v
VMODULES: OK, value: C:\Users\royce3\.vmodules
VTMP: OK, value: D:\temp\v_0

env VFLAGS: "-g -cc tcc"

Git version: git version 2.35.0.windows.1
Git vroot status: weekly.2023.25-36-gdd24e8a6 (1 commit(s) behind V master)
.git/config present: true

CC version: Error: exec failed (CreateProcess) with code 2: The system cannot find the file specified.
 cmd: cc --version
thirdparty/tcc status: thirdparty-windows-amd64 e90c2620
@remdragon remdragon added the Bug This tag is applied to issues which reports bugs. label Jun 26, 2023
@JalonSolov
Copy link
Contributor

You can simplify your code a bit to avoid the error, using a regular or block:

struct App{}

fn ( app &App ) myfunc4() {
        println( 'myfunc4' )
}

fn make[T]( app &T ) {
        $for method in T.methods {
                mut attmap := map[string]string
                for attr in method.attrs {
                        key, val := attr.split_once( ':' ) or { attr, '' }
                        attmap[key] = val.trim_left( ' ' )
                }
                println( attmap )
        }
}

fn main() {
        mut app := App{}
        make( app )
}

However, V does need to catch the error and give you a nicer message, rather than letting the C compiler fail.

@JalonSolov JalonSolov added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label Jun 26, 2023
@Delta456 Delta456 self-assigned this Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants