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

option sumtype is checking breaks #23486

Open
felipensp opened this issue Jan 16, 2025 · 4 comments
Open

option sumtype is checking breaks #23486

felipensp opened this issue Jan 16, 2025 · 4 comments
Labels
Bug This tag is applied to issues which reports bugs. Option Type Bugs/feature requests, that are related to `?Type`. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@felipensp
Copy link
Member

felipensp commented Jan 16, 2025

V version: V 0.4.9 d680c42, press to see full `v doctor` output
V full version V 0.4.9 ac71f9e.d680c42
OS linux, Ubuntu 24.04.1 LTS (WSL 2)
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8365U CPU @ 1.60GHz
Memory 5.54GB/7.67GB
V executable /home/felipe/v/v
V last modified time 2025-01-16 11:36:32
V home dir OK, value: /home/felipe/v
VMODULES OK, value: /home/felipe/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/felipe/v
Git version git version 2.43.0
V git status weekly.2025.1-62-gd49b8f9f (2 commit(s) behind V master)
.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 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status thirdparty-linux-amd64 0134e9b9
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.39-0ubuntu8.3) 2.39

What did you do?
./v -g -o vdbg cmd/v && ./vdbg bug.v && /home/felipe/v/bug

type Foo = int | string
struct Struct {
    a ?Foo
}

fn r(a string){}

fn t(s ?Foo) {
    mut t := Struct{a: s}
    if t.a is string {
        r(t.a)
    }
}
    
fn main() {
    s := ?Foo('hello')
    t(s)
}

What did you see?

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/bug.01JHQFSW2KWAQ1HHR895159XBV.tmp.c:5641: error: field not found: _typ
=================================================================
(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 .

What did you expect to see?

no crash

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 the Bug This tag is applied to issues which reports bugs. label Jan 16, 2025
Copy link

Connected to Huly®: V_0.6-21916

@spytheman
Copy link
Member

I think that it should be a checker error, since if t.a is string { , when the a field is declared as ?Foo, means that t.a should be unwrapped first.

@spytheman
Copy link
Member

spytheman commented Jan 16, 2025

I know that it makes the usage a bit clumsier, but on the other hand, the language rules are easier to apply for both the compiler and the programmer, i.e. option values have to always be unwrapped, before doing stuff on the value, when it is != none .

@spytheman
Copy link
Member

This for example should compile/run cleanly (it currently cgen errors, but for another reason):

type Foo = int | string
struct Struct {
    a ?Foo
}

fn r(a string){}

fn t(s ?Foo) {
	mut t := Struct{a: s}
	if t.a != none {
		if t.a is string {
		        r(t.a)
		}
	}
}
    
fn main() {
    s := ?Foo('hello')
    t(s)
}

@spytheman spytheman added Unit: Checker Bugs/feature requests, that are related to the type checker. 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. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Option Type Bugs/feature requests, that are related to `?Type`. labels Jan 16, 2025
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. Option Type Bugs/feature requests, that are related to `?Type`. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

No branches or pull requests

2 participants