v icon indicating copy to clipboard operation
v copied to clipboard

c error when using str() for a template with alias type

Open WoodyAtHome opened this issue 2 years ago • 1 comments

OS: linux, Ubuntu 20.04.5 LTS Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

getwd: /home/woody/sources/v/bugs vmodules: /home/woody/.vmodules vroot: /home/woody/sources/v/v vexe: /home/woody/sources/v/v/v vexe mtime: 2022-10-27 21:13:51 is vroot writable: true is vmodules writable: true V full version: V 0.3.1 d857e97.0ca5b1f

Git version: git version 2.25.1 Git vroot status: weekly.2022.43-24-g0ca5b1f6 .git/config present: true thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

What did you do? tmpl.v:

module main

pub struct Foo {
	x int
}

pub fn (foo Foo) str() string {
	return 'Foo.x = $foo.x'
}

pub struct Bar<T> {
	t T
}

fn (bar Bar<T>) str() string {
	return 'Bar.t = $bar.t.str()'
}

pub type MyFoo = Foo                    
//pub type BarMyFooArray = Bar<[]Foo>   // (20)
pub type BarMyFooArray = Bar<[]MyFoo>    // (21)

fn main() {
	_ := BarMyFooArray{}
}

// this file compiles with c error
// uncommenting line (20) and commenting (21) => compiles fine

What did you expect to see? v tmpl.v without error

What did you see instead?

/tmp/v_1000/type.2755742234228901151.tmp.c:12148: warning: cast between pointer and integer of different size
tcc: error: undefined symbol 'Array_main__Foo_str'
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

WoodyAtHome avatar Oct 27 '22 21:10 WoodyAtHome

Does not reproduces:

PS D:\Games\Proekti\V\interactions> type test2.v
module main

pub struct Foo {
        x int
}

pub fn (foo Foo) str() string {
        return 'Foo.x = ${foo.x}'
}

pub struct Bar[T] {
        t T
}

fn (bar Bar[T]) str() string {
        return 'Bar.t = ${bar.t.str()}'
}

pub type MyFoo = Foo

// pub type BarMyFooArray = Bar<[]Foo>   // (20)
pub type BarMyFooArray = Bar[[]MyFoo] // (21)

fn main() {
        _ := BarMyFooArray{}
}

// this file compiles with c error
// uncommenting line (20) and commenting (21) => compiles fine
PS D:\Games\Proekti\V\interactions> v version
V 0.4.4 2a68e2b
PS D:\Games\Proekti\V\interactions> v run test2.v 
PS D:\Games\Proekti\V\interactions> 

MCausc78 avatar Jan 26 '24 16:01 MCausc78