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

generic types compiler crash #22406

Open
kennyb opened this issue Oct 4, 2024 · 1 comment · May be fixed by #22413
Open

generic types compiler crash #22406

kennyb opened this issue Oct 4, 2024 · 1 comment · May be fixed by #22413
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. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@kennyb
Copy link

kennyb commented Oct 4, 2024

the compiler crashed when trying to implement a simple observable

V doctor:

V full version: V 0.4.8 5b1581d
OS: windows, Microsoft Windows 10 Home v19045 64-bit
Processor: 8 cpus, 64bit, little endian, 

getwd: C:\Users\Kenny\source\vtest
vexe: C:\Users\Kenny\source\v\v.exe
vexe mtime: 2024-10-04 05:53:52

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

Git version: git version 2.44.0.windows.1
Git vroot status: weekly.2024.18-807-g5b1581da
.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 Obv.v

// callback types
type CBnoret[T] = fn (val T)
type CBnoret2[T] = fn (val T, prev T)
type CBvret[T] = fn (val T) T
type CBvret2[T] = fn (val T, prev T) T

type Callback[T] = CBnoret[T] | CBnoret2[T] | CBvret[T] | CBvret2[T]

interface IObv[T] {
	v T
	prev T
	cb []Callback[T]
}

struct Obv[T] {
mut:
	v T
	prev T
	cb []Callback
}

fn (o Obv[T]) get () T {
	return o.v
}

fn (o Obv[T]) do_callbacks () T {

	return o.v
}

fn (mut o Obv[T]) set (new_value T) T {
	prev := o.v
	if prev != new_value {
		o.v = new_value
		o.prev = prev

	}

	return o.v
}

fn oo[T](init T) Obv[T] {
	return Obv[T]{v: init}
}


one := oo(1)
txt := oo("lala")

println("done")
println("done ${txt.get()}")
println("one: ${one.get()}")

txt.get()
one.get()

What did you expect to see?

no crash

What did you see instead?

================== C compilation error (from tcc): ==============
cc: C:/Users/Kenny/AppData/Local/Temp/v_0/Obv.01J9B30QWYW070ED4708QEWXXA.tmp.c:530: warning: WINVER redefined
cc: C:/Users/Kenny/AppData/Local/Temp/v_0/Obv.01J9B30QWYW070ED4708QEWXXA.tmp.c:1248: error: ';' expected (got "Array_main__Callback")
=================================================================
(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.

@felipensp felipensp added Bug This tag is applied to issues which reports bugs. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Oct 4, 2024
@felipensp felipensp linked a pull request Oct 5, 2024 that will close this issue
@felipensp felipensp self-assigned this Oct 5, 2024
@felipensp
Copy link
Member

It should be cb []Callback[T] instead of cb []Callback, a checker error must be added.

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. 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