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

will implicitly take embedded as receiver argument but not as any other argument #22796

Open
markfirmware opened this issue Nov 8, 2024 · 1 comment

Comments

@markfirmware
Copy link

markfirmware commented Nov 8, 2024

V doctor:

V full version: V 0.4.8 df4c6ac.1fc0531
OS: linux, Debian GNU/Linux 12 (bookworm) (VM)
Processor: 1 cpus, 64bit, little endian, DO-Premium-AMD

getwd: /home/user/github.com/markfirmware/stable
vexe: /home/user/github.com/vlang/v/v
vexe mtime: 2024-11-08 01:57:57

vroot: OK, value: /home/user/github.com/vlang/v
VMODULES: OK, value: /home/user/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.39.5
Git vroot status: weekly.2024.45-29-g1fc05315-dirty
.git/config present: true

CC version: cc (Debian 12.2.0-14) 12.2.0
emcc version: N/A
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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

struct Alpha {
  alpha int
  }
struct Bravo {
  Alpha
  bravo int
}
fn (x Alpha) f1() { println('Alpha in receiver ${x.alpha}') }
fn f2(x Alpha) { println('Alpha in arg 1 ${x.alpha}') }
fn main() {
  b := Bravo{}
  b.f1()
  f2(b) // note that b.Alpha will work
}

What did you expect to see?

compile no error

What did you see instead?

src/embedded.v:13:6: error: cannot use `Bravo` as `Alpha` in argument 1 to `f2`
   11 |   b := Bravo{}
   12 |   b.f1()
   13 |   f2(b) // note that b.Alpha will work
      |      ^
   14 | }

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

@JalonSolov
Copy link
Contributor

Bravo is not an Alpha (it just has one embedded in it), and f2 is expecting an Alpha.

If you want them to be treated the same, create an interface that they both implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants