1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

enums: make in work without specifying the full type

This commit is contained in:
Alexander Medvednikov 2019-10-24 15:41:29 +03:00
parent 560ae9352c
commit 3a929faf26
3 changed files with 17 additions and 13 deletions

View File

@ -1,13 +1,17 @@
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module builtin
fn C.memcpy(byteptr, byteptr, int)
fn C.memmove(byteptr, byteptr, int)
//fn C.malloc(int) byteptr
fn C.realloc(byteptr, int) byteptr
fn C.realloc(a byteptr, b int) byteptr
fn C.qsort(voidptr, int, int, voidptr)
fn C.sprintf(a ...voidptr) byteptr
// Windows
fn C._setmode(int, int)
fn C._fileno(int) int
//fn C.qsort()

View File

@ -1264,7 +1264,7 @@ fn (p mut Parser) gen(s string) {
// Generate V header from V source
fn (p mut Parser) statement(add_semi bool) string {
//p.expected_type = ''
p.expected_type = ''
if p.returns && !p.is_vweb {
p.error('unreachable code')
}
@ -1997,11 +1997,10 @@ fn (p mut Parser) get_c_func_type(name string) string {
cfn := p.table.find_fn(name) or {
// Not Found? Return 'void*'
//return 'cvoid' //'void*'
//if false {
if p.expected_type != '' && p.expected_type != 'void' {
p.warn('\ndefine imported C function with ' +
'`fn C.$name([args]) [return_type]`\n')
}
//if p.expected_type != '' && p.expected_type != 'void' {
//p.warn('\n e=$p.expected_type define imported C function with ' +
//'`fn C.$name([args]) [return_type]`\n')
//}
return 'void*'
}
// println("C fn $name has type $cfn.typ")

View File

@ -25,6 +25,7 @@ fn test_enum() {
fn test_in() {
color := Color.red
num := 3
num := 3 // used to be an expr bug before `in`
assert color in [.red, .green]
assert num == 3
}