v icon indicating copy to clipboard operation
v copied to clipboard

autofree causes incompatible type error

Open kokizzu opened this issue 4 years ago • 2 comments

V version: V 0.2 954580f, timestamp: 2020-12-28 20:29:58 +0200 OS: linux, Ubuntu 20.04.1 LTS

What did you do? run this code using -prod -autofree flag:

//////////////////////////////
// scomb.v
fn new_gap(gap1 int) int {
        mut gap := int(f64(gap1) / 1.3)
        if gap == 9 || gap == 10 {
                return 11
        }
        if gap < 1 {
                return 1
        }
        return gap
}

fn comb_sort(mut a []string) {
        xlen := a.len
        mut gap := xlen
        mut swapped := false
        for {
                swapped = false
                gap = new_gap(gap)
                for i := 0; i < xlen - gap; i++ {
                        if a[i] > a[i + gap] {
                                swapped = true
                                a[i], a[i + gap] = a[i + gap], a[i]
                        }
                }
                if !((gap > 1) || swapped) {
                        break
                }
        }
}

const (
        n = 10000000
)

fn main() {
        mut arr := []string{len: n}
        for z := 0; z < n; z++ {
                arr[z] = '${n - z}'
        }
        comb_sort(mut arr)
        for z := 1; z < n; z++ {
                if arr[z] < arr[z - 1] {
                        println('!')
                }
        }
}

What did you expect to see? no error

What did you see instead?

==================
/tmp/v/scomb.2078404398143398576.tmp.c: In function ‘main__comb_sort’:
/tmp/v/scomb.2078404398143398576.tmp.c:9358:62: error: incompatible type for argument 1 of ‘string_clone’
 9358 |     string _var_405 = *(string*)array_get(*/*1*/string_clone(a), i);
      |                                                              ^
      |                                                              |
      |                                                              array_string * {aka array *}
/tmp/v/scomb.2078404398143398576.tmp.c:7793:28: note: expected ‘string’ but argument is of type ‘array_string *’ {aka ‘array *’}
 7793 | string string_clone(string a) {
      |                     ~~~~~~~^
/tmp/v/scomb.2078404398143398576.tmp.c:9359:62: error: incompatible type for argument 1 of ‘string_clone’
 9359 |     string _var_411 = *(string*)array_get(*/*1*/string_clone(a), i + gap);
      |                                                              ^
...
==================
(Use `v -cg` to print the entire error message)

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

If you were not working with C interop, please raise an issue on GitHub:

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

Command exited with non-zero status 1

CPU: 0.14s      Real: 0.16s     RAM: 35264KB

kokizzu avatar Dec 28 '20 20:12 kokizzu

Still here (V 0.2.4)

ArtemkaKun avatar Feb 12 '22 16:02 ArtemkaKun

Hi, still present. For the latest V (0.2.4; actual for 06.05.2022), errors are the following:

-autofree

==================
/tmp/v_1000/v-bugs.14482822203030645889.tmp.c:11906: error: cannot convert 'struct array *' to 'struct string'
...
==================
(Use `v -cg` to print the entire error message)

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

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

-prod -autofree

==================
/tmp/v_1000/v-bugs.4785273952277292112.tmp.c: In function ‘main__comb_sort’:
/tmp/v_1000/v-bugs.4785273952277292112.tmp.c:11880:90: error: incompatible type for argument 1 of ‘string_clone’
11880 |                                 string _var_363 = *(string*)array_get(*/*1*/string_clone(a), i);
|                                                                                          ^
|                                                                                          |
|                                                                                          Array_string * {aka array *}
/tmp/v_1000/v-bugs.4785273952277292112.tmp.c:9208:28: note: expected ‘string’ but argument is of type ‘Array_string *’ {aka ‘array *’}
9208 | string string_clone(string a) {
|                     ~~~~~~~^
/tmp/v_1000/v-bugs.4785273952277292112.tmp.c:11881:90: error: incompatible type for argument 1 of ‘string_clone’
11881 |                                 string _var_369 = *(string*)array_get(*/*1*/string_clone(a), i + gap);
|                                                                                          ^
...
==================
(Use `v -cg` to print the entire error message)

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

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

ArtemkaKun avatar May 06 '22 18:05 ArtemkaKun