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

Cannot assign interface pointer to struct initialization: error: cannot assign a pointer to option struct field #23879

Closed
daansystems opened this issue Mar 8, 2025 · 1 comment · Fixed by #23880
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@daansystems
Copy link

daansystems commented Mar 8, 2025

V version: V 0.4.9 e66e996, press to see full `v doctor` output
V full version V 0.4.9 5c65e58.e66e996
OS windows, Microsoft Windows 11 Pro 26100 64-bit
Processor 24 cpus, 64bit, little endian, AMD Ryzen 9 3900X 12-Core Processor
Memory 18.64GB/31.9GB
V executable C:\v\v.exe
V last modified time 2025-03-08 10:49:50
V home dir OK, value: C:\v
VMODULES OK, value: C:\Users\info.vmodules
VTMP OK, value: C:\Users\info\Documents\MobaXterm\slash\mx86_64b\var\log\xwin\v_0
Current working dir OK, value: D:\vbug2
Git version git version 2.42.0.windows.2
V git status weekly.2025.08-112-ge66e9960-dirty
.git/config present true
cc version N/A
gcc version N/A
clang version clang version 17.0.1
msvc version N/A
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status thirdparty-windows-amd64 b425ac82
emcc version N/A
glibc version ldd (cygwin) 3.4.7

What did you do?
./v -g -o vdbg cmd/v && ./vdbg main.v && D:\vbug2\main.exe

module main

@[heap]
interface IGameObject {
mut:
	name     string
	parent   ?&IGameObject
}

@[heap]
struct GameObject implements IGameObject {
mut:
	name     string
	parent   ?&IGameObject
}

struct Ship implements IGameObject {
	GameObject
	speed f32
}

fn main() {
	mut world := &GameObject{
		name: 'world'
	}
	mut ship := &Ship{
		name: 'ship',
		parent: world
	}
	eprintln("ship: ${ship}")
}

What did you see?

main.v:28:3: error: cannot assign a pointer to option struct field
   26 |     mut ship := &Ship{
   27 |         name: 'ship',
   28 |         parent: world
      |         ~~~~~~~~~~~~~
   29 |     }
   30 |     eprintln("ship: ${ship}")

What did you expect to see?

no v error

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.

Copy link

Connected to Huly®: V_0.6-22282

@felipensp felipensp self-assigned this Mar 8, 2025
@felipensp felipensp added Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker. labels Mar 8, 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. 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