V: Type casting bug

Created on 31 Dec 2019  路  4Comments  路  Source: vlang/v

V version: V 0.1.24 51222ba
OS: Void linux(glibc)

What did you do?

module main

fn main() {
    n := 123 as string
    println(n)
}

What did you expect to see?
123

What did you see instead?

/tmp/v/test2.tmp.c: In function 'main__main':
/tmp/v/test2.tmp.c:3915:1: error: conversion to non-scalar type requested
 3915 | string n=(string)( 123 ) ;
      | ^~~~~~
V error: C error. This should never happen.
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose
Bug

All 4 comments

I'll be leaving this open until we get a better error message but what you are looking for is probably 123.str()

@lutherwenxu do we really need to do that? as casting was added and removed immediately. If you meant that should give an error message as casting is only for sum types or a similar to it then I don't think it's needed.

I just mean ANY V error would work. It just shouldn't result in a C error.

Fixed:

 `as` casts have been removed, use the old syntax: `Type(val)`
Was this page helpful?
0 / 5 - 0 ratings

Related issues

penguindark picture penguindark  路  3Comments

vtereshkov picture vtereshkov  路  3Comments

ArcDrake picture ArcDrake  路  3Comments

XVilka picture XVilka  路  3Comments

markgraydev picture markgraydev  路  3Comments