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

What happens if you use pointer access and transformation to access memory when testing multiple structs and interfaces related to each other? #22237

Open
ipsfsw opened this issue Sep 16, 2024 · 0 comments

Comments

@ipsfsw
Copy link

ipsfsw commented Sep 16, 2024

V doctor:

V full version: V 0.4.7 cc7665f.ca5f47a
OS: windows, Microsoft Windows 11 Pro v22631 64-bit
Processor: 6 cpus, 64bit, little endian, 

getwd: D:\coding\other\v\test_v
vexe: D:\devmt\lang\other\v\v.exe
vexe mtime: 2024-09-16 04:56:42

vroot: OK, value: D:\devmt\lang\other\v
VMODULES: OK, value: C:\Users\ipsfsw\.vmodules
VTMP: OK, value: C:\Users\ipsfsw\AppData\Local\Temp\v_0

Git version: git version 2.42.0.windows.2
Git vroot status: weekly.2024.37-3-gca5f47a9 (4 commit(s) behind V master)
.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 b425ac82

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

module main

interface ITA {
	nam string
	info()
}

fn (i ITA) hello() {
	println('hello')
}

interface ITB {
	nam string
	info()
}

struct TSA {
	nam string
	age int
}

fn (t TSA) info() {
	println('TSA { name : ${t.nam}, age : ${t.age} }')
}

fn (t TSA) ttt() {
	println('${t.nam} // ${t.age}')
}

struct TSB {
	nam string
	age int
}

fn (t TSB) info() {
	println('TSB { name : ${t.nam}, age : ${t.age} }')
}

type TSAB = TSA | TSB

fn (t TSAB) info() {
	println('TSAB info ········· ')
	match t {
		TSA {
			t.info()
			tt := t as TSA
			tt.info()
			mut itaf := &TSA(&t).ttt
			itaf()
			ita := &ITA(&tt)
			ita.hello()
			// error
			itaf = ita.hello
		}
		TSB {
			t.info()
			tt := t as TSB
			tt.info()
		}
	}
	ita := &TSA(&t)
	ita.ttt()
}

fn test_ts(t TSAB) {
	t.info()
}

fn main() {
	test_ts(nam: 'mytype?', age: 10)
}

What did you expect to see?

TSAB info ·········
TSA { name : , age : 0 }
TSA { name : , age : 0 }
// 0
hello
?�F@�Fmm m // 0

What did you see instead?

================== C compilation error (from tcc): ==============
cc: d:/devmt/lang/other/v/thirdparty/tcc/include/winapi/synchapi.h:167: warning: CreateMutex redefined
cc: C:/Users/ipsfsw/AppData/Local/Temp/v_0/main.01J7Y00ABDPRDNKMSB9PMY3B09.tmp.c:2648: error: field not found: _method_hello
... (the original output was 8 lines long, and was truncated to 2 lines)
=================================================================
(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 .

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.

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

1 participant