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

overloading operator c compiler error lvalue expected #22297

Closed
daansystems opened this issue Sep 24, 2024 · 0 comments · Fixed by #22304
Closed

overloading operator c compiler error lvalue expected #22297

daansystems opened this issue Sep 24, 2024 · 0 comments · Fixed by #22304
Labels
Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@daansystems
Copy link

daansystems commented Sep 24, 2024

V doctor:

V full version: V 0.4.7 18eee34.4ee948f
OS: windows, Microsoft Windows 11 Pro v22631 64-bit
Processor: 24 cpus, 64bit, little endian, 

getwd: D:\vbug
vexe: C:\v\v.exe
vexe mtime: 2024-09-24 17:12:18

vroot: OK, value: C:\v
VMODULES: OK, value: C:\Users\info\.vmodules
VTMP: OK, value: C:\Users\info\AppData\Local\Temp\v_0

Git version: git version 2.42.0.windows.2
Git vroot status: weekly.2024.39-5-g4ee948fe-dirty
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,

operable program or batch file.


thirdparty/tcc status: thirdparty-windows-amd64 b425ac82

What did you do?
./v -g -o vdbg cmd/v && ./vdbg src\main.v

module main

import math
import math.vec

type Vector3 = vec.Vec3[f32]

fn vector3(x f32, y f32, z f32) Vector3 {
	return Vector3{x, y, z}
}

pub type Matrix4 = [16]f32

pub fn matrix4(x0 f32, x1 f32, x2 f32, x3 f32, x4 f32, x5 f32, x6 f32, x7 f32, x8 f32, x9 f32, x10 f32, x11 f32, x12 f32, x13 f32, x14 f32, x15 f32) Matrix4 {
	return [
		x0,
		x1,
		x2,
		x3,
		x4,
		x5,
		x6,
		x7,
		x8,
		x9,
		x10,
		x11,
		x12,
		x13,
		x14,
		x15,
	]!
}

pub fn (x Matrix4) str() string {
	return '|${x[0]:-6.3},${x[1]:-6.3},${x[2]:-6.3},${x[3]:-6.3}|\n' +
		'|${x[4]:-6.3},${x[5]:-6.3},${x[6]:-6.3},${x[7]:-6.3}|\n' +
		'|${x[8]:-6.3},${x[9]:-6.3},${x[10]:-6.3},${x[11]:-6.3}|\n' +
		'|${x[12]:-6.3},${x[13]:-6.3},${x[14]:-6.3},${x[15]:-6.3}|'
}

pub fn matrix4_unit() Matrix4 {
	return matrix4(f32(1), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
}

pub fn (a Matrix4) * (b Matrix4) Matrix4 {
	mut res := Matrix4{}
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			res[j * 4 + i] = 0
			for k := 0; k < 4; k++ {
				res[j * 4 + i] += a[k * 4 + i] * b[j * 4 + k]
			}
		}
	}
	return res
}

pub fn rotate(angle f32, w Vector3) Matrix4 {
	cs := f32(math.cos(angle))
	sn := f32(math.sin(angle))
	cv := f32(1.0) - cs
	axis := w.normalize()

	ax := axis.x
	ay := axis.y
	az := axis.z

	return matrix4((ax * ax * cv) + cs, (ax * ay * cv) + az * sn, (ax * az * cv) - ay * sn,
		0, (ay * ax * cv) - az * sn, (ay * ay * cv) + cs, (ay * az * cv) + ax * sn, 0,
		(az * ax * cv) + ay * sn, (az * ay * cv) - ax * sn, (az * az * cv) + cs, 0, 0,
		0, 0, 1)
}

fn main() {
	mut rot := matrix4_unit()
	rot *= rotate(0.5, vector3(0.5, 0.5, 0.5))
	println("rot: ${rot}")
}

What did you expect to see?

no c compiler error

What did you see instead?

================== C compilation error (from tcc): ==============
cc: C:/Users/info/AppData/Local/Temp/v_0/main.01J8JHFZVMCNTEQEV37Q4DTYPF.tmp.c:7539: warning: implicit declaration of function 'tcc_backtrace'
cc: C:/Users/info/AppData/Local/Temp/v_0/main.01J8JHFZVMCNTEQEV37Q4DTYPF.tmp.c:17222: error: lvalue expected
... (the original output was 3 lines long, and was truncated to 2 lines)
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

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.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. labels Sep 25, 2024
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. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants