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

parser: disallow statements after a return, branch check $if, $else, switch, and loops correctly

This commit is contained in:
Julian Schurhammer
2019-08-10 20:26:42 +12:00
committed by Alexander Medvednikov
parent 58b52aa9fb
commit 1864e92ff4
26 changed files with 97 additions and 94 deletions

View File

@@ -77,7 +77,6 @@ pub fn (a mut array) sort_with_compare(compare voidptr) {
pub fn (a mut array) insert(i int, val voidptr) {
if i >= a.len {
panic('array.insert: index larger than length')
return
}
a._push(val)
size := a.element_size

View File

@@ -18,7 +18,9 @@ fn on_panic(f fn (int) int) {
}
pub fn print_backtrace() {
return
if true {
return // TODO
}
$if mac {
buffer := [100]voidptr
nr_ptrs := C.backtrace(buffer, 100)

View File

@@ -94,8 +94,7 @@ fn (n & Node) find(key string, out voidptr, element_size int) bool{
} else {
return n.right.find(key, out, element_size)
}
}
return false
}
}
// same as `find`, but doesn't return a value. Used by `exists`
@@ -116,8 +115,7 @@ fn (n & Node) find2(key string, element_size int) bool{
} else {
return n.right.find2(key, element_size)
}
}
return false
}
}
fn (m mut map) _set(key string, val voidptr) {
@@ -215,7 +213,6 @@ pub fn (m mut map) delete(key string) {
pub fn (m map) exists(key string) bool {
panic('map.exists(key) was removed from the language. Use `key in map` instead.')
return false
}
fn (m map) _exists(key string) bool {

View File

@@ -40,7 +40,6 @@ pub fn tos(s byteptr, len int) string {
pub fn tos_clone(s byteptr) string {
if isnil(s) {
panic('tos: nil string')
return string{}
}
len := strlen(s)
res := tos(s, len)
@@ -52,7 +51,6 @@ pub fn tos_clone(s byteptr) string {
fn tos2(s byteptr) string {
if isnil(s) {
panic('tos2: nil string')
return string{}
}
len := C.strlen(s)
res := tos(s, len)
@@ -337,7 +335,6 @@ pub fn (s string) right(n int) string {
pub fn (s string) substr(start, end int) string {
if start > end || start > s.len || end > s.len || start < 0 || end < 0 {
panic('substr($start, $end) out of bounds (len=$s.len)')
return ''
}
len := end - start

View File

@@ -84,7 +84,8 @@ struct Cfg {
fn ft_load_char(_face Face, code i64) Character {
// #FT_Face face = *(FT_Face*)(_face); FT_ULong code = *(FT_ULong*)(code);
# FT_Face face = *((FT_Face*)_face.cobj);
# if (FT_Load_Char(face, code, FT_LOAD_RENDER))
# int condition = FT_Load_Char(face, code, FT_LOAD_RENDER);
if (C.condition != 0)
{
println('freetype: Failed to load Glyph')
exit(1)
@@ -170,7 +171,8 @@ pub fn new_context(cfg gg.Cfg) *Context {
}
println('Trying to load font from $font_path')
# FT_Face face;
# if (FT_New_Face(ft, font_path.str, 0, &face))
# int condition = FT_New_Face(ft, font_path.str, 0, &face);
if (C.condition != 0)
// # if (FT_New_Face(ft, "/Library/Fonts/Courier New.ttf", 0, &face))
// # if (FT_New_Face(ft, "/System/Library/Fonts/Apple Color Emoji.ttc", 0, &face))
{

View File

@@ -274,7 +274,7 @@ pub fn (ctx &GG) draw_rect2(x, y, w, h f32, c gx.Color) {
fn todo_remove_me(cfg Cfg, scale int) {
// Can only have text in ortho mode
if !cfg.use_ortho {
return &GG{}
return
}
mut width := cfg.width * scale
mut height := cfg.height * scale

View File

@@ -169,22 +169,18 @@ fn build_request_headers(user_agent, method, host_name, path string) string {
pub fn unescape_url(s string) string {
panic('http.unescape_url() was replaced with urllib.query_unescape()')
return ''
}
pub fn escape_url(s string) string {
panic('http.escape_url() was replaced with urllib.query_escape()')
return ''
}
pub fn unescape(s string) string {
panic('http.unescape() was replaced with http.unescape_url()')
return ''
}
pub fn escape(s string) string {
panic('http.escape() was replaced with http.escape_url()')
return ''
}
type wsfn fn (s string, ptr voidptr)

View File

@@ -9,7 +9,6 @@ fn test_parse_user() {
s := '{"age": 10, "nums": [1,2,3]}'
u := json.decode(User, s) or {
exit(1)
return
}
assert u.age == 10
assert u.nums.len == 3

View File

@@ -39,7 +39,6 @@ fn (l Log) log_file(s string, e string) {
filename := l.output
f := os.open_append(l.output) or {
panic('error reading file $filename')
return
}
timestamp := time.now().format_ss()
f.writeln('$timestamp [$e] $s')

View File

@@ -19,7 +19,6 @@ pub fn fraction(n i64, d i64) Fraction{
}
else {
panic('Denominator cannot be zero')
return Fraction{} // TODO remove return
}
}

View File

@@ -870,6 +870,7 @@ pub fn fork() int {
pid := C.fork()
return pid
}
panic('os.fork not supported in windows') // TODO
}
pub fn wait() int {
@@ -877,6 +878,7 @@ pub fn wait() int {
pid := C.wait(0)
return pid
}
panic('os.wait not supported in windows') // TODO
}
pub fn file_last_mod_unix(path string) int {

View File

@@ -27,7 +27,6 @@ fn test_write_and_read_string_to_file() {
read_hello := os.read_file(filename) or {
panic('error reading file $filename')
return
}
assert hello == read_hello

View File

@@ -40,6 +40,7 @@ pub fn get_module_filename(handle HANDLE) ?string {
return error('Cannot get file name from handle.')
}
}
panic('this should be unreachable') // TODO remove unreachable after loop
}
// Ref - https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessagea#parameters

View File

@@ -17,13 +17,11 @@ pub fn compile_template(path string) string {
//lines := os.read_lines(path)
mut html := os.read_file(path) or {
panic('html failed')
return ''
}
mut header := ''
if os.file_exists('header.html') {
h := os.read_file('header.html') or {
panic('html failed')
return ''
}
header = h.replace('\'', '"')
}

View File

@@ -85,13 +85,12 @@ $html
pub fn run<T>(port int) {
println('Running vweb app on http://localhost:$port ...')
l := net.listen(port) or { panic('failed to listen') return }
l := net.listen(port) or { panic('failed to listen') }
mut app := T{}
app.init()
for {
conn := l.accept() or {
panic('accept() failed')
return
}
// TODO move this to handle_conn<T>(conn, app)
s := conn.read_line()