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

checker, generics: X is T does not work #23282

Closed
Le0Developer opened this issue Dec 27, 2024 · 0 comments · Fixed by #23309
Closed

checker, generics: X is T does not work #23282

Le0Developer opened this issue Dec 27, 2024 · 0 comments · Fixed by #23309
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@Le0Developer
Copy link
Member

Le0Developer commented Dec 27, 2024

V doctor:

V full version: V 0.4.9 5b44b67
OS: macos, macOS, 15.2, 24C101
Processor: 8 cpus, 64bit, little endian, Apple M2

getwd: /Users/leodev/p/v/cluedo
vexe: /Users/leodev/p/v/v/v
vexe mtime: 2024-12-27 12:16:03

vroot: OK, value: /Users/leodev/p/v/v
VMODULES: OK, value: /Users/leodev/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.5 (Apple Git-154)
Git vroot status: weekly.2024.52-6-g5b44b672
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.6)
emcc version: N/A
thirdparty/tcc status: thirdparty-macos-arm64 713692d4

What did you do?
./v -g -o vdbg cmd/v && ./vdbg repro.v

type Sumtype = string | int

fn generic_fn[T]() ?T {
	a := Sumtype('123')
	if a is T {
		return a
	}

	b := Sumtype(123)
	if b is T {
		return b
	}

	return none
}

fn main() {
	println(generic_fn[string]())
	println(generic_fn[int]())
}

What did you expect to see?

Successful compilation

What did you see instead?

repro.v:6:10: error: `Sumtype` has no variant `T`
    4 | fn generic_fn[T]() ?T {
    5 |     a := Sumtype('123')
    6 |     if a is T {
      |             ^
    7 |         return a
    8 |     }
repro.v:11:10: error: `Sumtype` has no variant `T`
    9 | 
   10 |     b := Sumtype(123)
   11 |     if b is T {
      |             ^
   12 |         return b
   13 |     }

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.

Huly®: V_0.6-21714

@Le0Developer Le0Developer added Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker. labels Dec 27, 2024
@Le0Developer Le0Developer changed the title checker, generics: X is T does not work if X is a sumtype checker, generics: X is T does not work Dec 27, 2024
@felipensp felipensp self-assigned this Dec 29, 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. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants