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

The error "cannot use &T as &Y in argument 1 to func" is printed twice #20709

Closed
zeozeozeo opened this issue Feb 2, 2024 · 0 comments · Fixed by #20910
Closed

The error "cannot use &T as &Y in argument 1 to func" is printed twice #20709

zeozeozeo opened this issue Feb 2, 2024 · 0 comments · Fixed by #20910
Labels
Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@zeozeozeo
Copy link
Contributor

zeozeozeo commented Feb 2, 2024

V doctor:

V full version: V 0.4.4 5306469.0a612bf
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 20 cpus, 64bit, little endian, 

getwd: C:\Users\user\Desktop\Code\leaflang
vexe: C:\Users\user\Desktop\Code\v\v.exe
vexe mtime: 2024-02-02 11:02:48

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

Git version: git version 2.42.0.windows.1
Git vroot status: weekly.2024.05-12-g0a612bf6
.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 a39eb79b

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

struct Foo {
mut:
	x int
}

struct Bar {
mut:
	y int
}

type Foobar = Foo | Bar

fn mutate_foobar(mut foobar Foobar) {
	match foobar {
		Foo {
			mutate_foo(mut foobar)
		}
		Bar {
			mutate_bar(mut foobar)
		}
	}
}

fn mutate_foo(mut foo Foo) {
	foo.x = 5
}

fn mutate_bar(mut bar Bar) {
	bar.y = 10
}

fn main() {
	mut bar := Bar{y: 0}
	mutate_foobar(mut bar)
}

What did you expect to see?

Two errors being printed instead of 4

What did you see instead?

test.v:16:19: error: cannot use `&Foobar` as `&Foo` in argument 1 to `mutate_foo`
   14 |     match foobar {
   15 |         Foo {
   16 |             mutate_foo(mut foobar)
      |                            ~~~~~~
   17 |         }
   18 |         Bar {
test.v:16:19: error: cannot use `&Foobar` as `&Foo` in argument 1 to `mutate_foo`
   14 |     match foobar {
   15 |         Foo {
   16 |             mutate_foo(mut foobar)
      |                            ~~~~~~
   17 |         }
   18 |         Bar {
test.v:19:19: error: cannot use `&Foobar` as `&Bar` in argument 1 to `mutate_bar`
   17 |         }
   18 |         Bar {
   19 |             mutate_bar(mut foobar)
      |                            ~~~~~~
   20 |         }
   21 |     }
test.v:19:19: error: cannot use `&Foobar` as `&Bar` in argument 1 to `mutate_bar`
   17 |         }
   18 |         Bar {
   19 |             mutate_bar(mut foobar)
      |                            ~~~~~~
   20 |         }
   21 |     }

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 Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. label Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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