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

initializing fn field with matching fn function fails when parameter is a reference #16291

Open
d-p-y opened this issue Nov 2, 2022 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@d-p-y
Copy link
Contributor

d-p-y commented Nov 2, 2022

V doctor

OS: linux, Ubuntu 22.04.1 LTS
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 3700X 8-Core Processor
CC version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0

getwd: /home/dominik
vmodules: /home/dominik/.vmodules
vroot: /home/dominik/Projects/vlang
vexe: /home/dominik/Projects/vlang/v
vexe mtime: 2022-11-02 08:49:06
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.2 e5d1881.0aa2c63

Git version: git version 2.34.1
Git vroot status: 0.3.2-15-g0aa2c63a (2 commit(s) behind V master)
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

What did you do?


type FnWorkaround = fn (&int) int

pub struct Struct1 {
	works1 fn (int) int

	works2 fn (&int) int //this doesn't work (as all other 'even' arguments underneath)
	workaround FnWorkaround //this works
	
	works3 fn (u32) int
	works4 fn (&u32) int

	works5 fn(i64) int
	works6 fn(&i64) int

	works7 fn(u64) int
	works8 fn(&u64) int

	works9 fn(u8) int
	works10 fn(&u8) int

	works11 fn(i8) int
	works12 fn(&i8) int

	works13 fn(rune) int
	works14 fn(&rune) int

	works15 fn(f32) int
	works16 fn(&f32) int

	works17 fn(f64) int
	works18 fn(&f64) int

	works19 fn(i16) int
	works20 fn(&i16) int

	works21 fn(u16) int
	works22 fn(&u16) int
}

fn wrk1(x int) int {
	return 0
}

fn wrk2(x &int) int {
	return 0
}

fn wrk3(x u32) int {
	return 0
}

fn wrk4(x &u32) int {
	return 0
}

fn wrk5(x i64) int {
	return 0
}
fn wrk6(x &i64) int {
	return 0
}

fn wrk7(x u64) int {
	return 0
}

fn wrk8(x &u64) int {
	return 0
}

fn wrk9(x u8) int {
	return 0
}

fn wrk10(x &u8) int {
	return 0
}

fn wrk11(x i8) int {
	return 0
}

fn wrk12(x &i8) int {
	return 0
}

fn wrk13(x rune) int {
	return 0
}

fn wrk14(x &rune) int {
	return 0
}

fn wrk15(x f32) int {
	return 0
}

fn wrk16(x &f32) int {
	return 0
}

fn wrk17(x f64) int {
	return 0
}

fn wrk18(x &f64) int {
	return 0
}

fn wrk19(x i16) int {
	return 0
}

fn wrk20(x &i16) int {
	return 0
}

fn wrk21(x u16) int {
	return 0
}

fn wrk22(x &u16) int {
	return 0
}

fn main() {
	x := &Struct1{
		works1:wrk1,
		works2:wrk2,
		works3:wrk3,
		works4:wrk4,
		works5:wrk5,
		works6:wrk6,
		works7:wrk7,
		works8:wrk8,
		works9:wrk9,
		works10:wrk10,
		works11:wrk11,
		works12:wrk12,
		works13:wrk13,
		works14:wrk14,
		works15:wrk15,
		works16:wrk16,
		works17:wrk17,
		works18:wrk18,
		works19:wrk19,
		works20:wrk20,
		works21:wrk21,
		works22:wrk22
	}

	println("ok $x")
}

$ v run bug6.v

What did you expect to see?

ok [something] on console

What did you see instead?

bug6.v:132:3: error: cannot assign to field `works2`: expected `fn (int) int`, not `fn (&int) int`
  130 |     x := &Struct1{
  131 |         works1:wrk1,
  132 |         works2:wrk2,
      |         ~~~~~~~~~~~
  133 |         works3:wrk3,
  134 |         works4:wrk4,
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
bug6.v:134:3: error: cannot assign to field `works4`: expected `fn (u32) int`, not `fn (&u32) int`
  132 |         works2:wrk2,
  133 |         works3:wrk3,
  134 |         works4:wrk4,
      |         ~~~~~~~~~~~
  135 |         works5:wrk5,
  136 |         works6:wrk6,
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
bug6.v:136:3: error: cannot assign to field `works6`: expected `fn (i64) int`, not `fn (&i64) int`
  134 |         works4:wrk4,
  135 |         works5:wrk5,
  136 |         works6:wrk6,
      |         ~~~~~~~~~~~
  137 |         works7:wrk7,
  138 |         works8:wrk8,
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
bug6.v:138:3: error: cannot assign to field `works8`: expected `fn (u64) int`, not `fn (&u64) int`
  136 |         works6:wrk6,
  137 |         works7:wrk7,
  138 |         works8:wrk8,
      |         ~~~~~~~~~~~
  139 |         works9:wrk9,
  140 |         works10:wrk10,
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
bug6.v:140:3: error: cannot assign to field `works10`: expected `fn (u8) int`, not `fn (&u8) int`
  138 |         works8:wrk8,
  139 |         works9:wrk9,
  140 |         works10:wrk10,
      |         ~~~~~~~~~~~~~
  141 |         works11:wrk11,
  142 |         works12:wrk12,
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
bug6.v:142:3: error: cannot assign to field `works12`: expected `fn (i8) int`, not `fn (&i8) int`
  140 |         works10:wrk10,
  141 |         works11:wrk11,
  142 |         works12:wrk12,
      |         ~~~~~~~~~~~~~
  143 |         works13:wrk13,
  144 |         works14:wrk14,
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
bug6.v:144:3: error: cannot assign to field `works14`: expected `fn (rune) int`, not `fn (&rune) int`
  142 |         works12:wrk12,
  143 |         works13:wrk13,
  144 |         works14:wrk14,
      |         ~~~~~~~~~~~~~
  145 |         works15:wrk15,
  146 |         works16:wrk16,
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
bug6.v:146:3: error: cannot assign to field `works16`: expected `fn (f32) int`, not `fn (&f32) int`
  144 |         works14:wrk14,
  145 |         works15:wrk15,
  146 |         works16:wrk16,
      |         ~~~~~~~~~~~~~
  147 |         works17:wrk17,
  148 |         works18:wrk18,
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
bug6.v:148:3: error: cannot assign to field `works18`: expected `fn (f64) int`, not `fn (&f64) int`
  146 |         works16:wrk16,
  147 |         works17:wrk17,
  148 |         works18:wrk18,
      |         ~~~~~~~~~~~~~
  149 |         works19:wrk19,
  150 |         works20:wrk20,
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
bug6.v:150:3: error: cannot assign to field `works20`: expected `fn (i16) int`, not `fn (&i16) int`
  148 |         works18:wrk18,
  149 |         works19:wrk19,
  150 |         works20:wrk20,
      |         ~~~~~~~~~~~~~
  151 |         works21:wrk21,
  152 |         works22:wrk22
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
bug6.v:152:3: error: cannot assign to field `works22`: expected `fn (u16) int`, not `fn (&u16) int`
  150 |         works20:wrk20,
  151 |         works21:wrk21,
  152 |         works22:wrk22
      |         ~~~~~~~~~~~~~
  153 |     }
  154 |
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer

@d-p-y d-p-y added the Bug This tag is applied to issues which reports bugs. label Nov 2, 2022
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.
Projects
None yet
Development

No branches or pull requests

1 participant