checker: warn about automatic (de)referencing; freetype: compilation flag fixes
							parent
							
								
									69dff4b384
								
							
						
					
					
						commit
						bb5958991c
					
				| 
						 | 
					@ -158,7 +158,7 @@ FONS_DEF void fonsDrawDebug(FONScontext* s, float x, float y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Use FreeType on non-Windows systems
 | 
					// Use FreeType on non-Windows systems
 | 
				
			||||||
#ifndef _WIN32
 | 
					#ifndef _WIN32
 | 
				
			||||||
#define FONS_USE_FREETYPE
 | 
					//#define FONS_USE_FREETYPE
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef _WIN32
 | 
					#ifdef _WIN32
 | 
				
			||||||
| 
						 | 
					@ -172,7 +172,7 @@ FONS_DEF void fonsDrawDebug(FONScontext* s, float x, float y);
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#undef FONS_USE_FREETYPE
 | 
					//#undef FONS_USE_FREETYPE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//#define FONS_USE_FREETYPE 1
 | 
					//#define FONS_USE_FREETYPE 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1260,7 +1260,7 @@ fn compare_strings_by_len(a &string, b &string) int {
 | 
				
			||||||
fn compare_lower_strings(a &string, b &string) int {
 | 
					fn compare_lower_strings(a &string, b &string) int {
 | 
				
			||||||
	aa := a.to_lower()
 | 
						aa := a.to_lower()
 | 
				
			||||||
	bb := b.to_lower()
 | 
						bb := b.to_lower()
 | 
				
			||||||
	return compare_strings(aa, bb)
 | 
						return compare_strings(&aa, &bb)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// sort sorts the string array.
 | 
					// sort sorts the string array.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
module fontstash
 | 
					module fontstash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define FONS_USE_FREETYPE
 | 
					#define FONS_USE_FREETYPE 1
 | 
				
			||||||
#flag windows -I @VROOT/thirdparty/freetype/include
 | 
					#flag windows -I @VROOT/thirdparty/freetype/include
 | 
				
			||||||
#flag windows -L @VROOT/thirdparty/freetype/win64
 | 
					#flag windows -L @VROOT/thirdparty/freetype/win64
 | 
				
			||||||
#flag linux -I/usr/include/freetype2
 | 
					#flag linux -I/usr/include/freetype2
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -114,7 +114,7 @@ pub fn now() Time {
 | 
				
			||||||
	// in this API call
 | 
						// in this API call
 | 
				
			||||||
	t := C.time(0)
 | 
						t := C.time(0)
 | 
				
			||||||
	now := C.localtime(&t)
 | 
						now := C.localtime(&t)
 | 
				
			||||||
	return convert_ctime(now, 0)
 | 
						return convert_ctime(*now, 0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// utc returns the current UTC time.
 | 
					// utc returns the current UTC time.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2040,7 +2040,7 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for i, call_arg in call_expr.args {
 | 
						for i, call_arg in call_expr.args {
 | 
				
			||||||
		arg := if f.is_variadic && i >= f.params.len - 1 {
 | 
							param := if f.is_variadic && i >= f.params.len - 1 {
 | 
				
			||||||
			f.params[f.params.len - 1]
 | 
								f.params[f.params.len - 1]
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			f.params[i]
 | 
								f.params[i]
 | 
				
			||||||
| 
						 | 
					@ -2050,39 +2050,39 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
 | 
				
			||||||
				c.error('too many arguments in call to `$f.name`', call_expr.pos)
 | 
									c.error('too many arguments in call to `$f.name`', call_expr.pos)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		c.expected_type = arg.typ
 | 
							c.expected_type = param.typ
 | 
				
			||||||
		typ := c.check_expr_opt_call(call_arg.expr, c.expr(call_arg.expr))
 | 
							typ := c.check_expr_opt_call(call_arg.expr, c.expr(call_arg.expr))
 | 
				
			||||||
		call_expr.args[i].typ = typ
 | 
							call_expr.args[i].typ = typ
 | 
				
			||||||
		typ_sym := c.table.get_type_symbol(typ)
 | 
							typ_sym := c.table.get_type_symbol(typ)
 | 
				
			||||||
		arg_typ_sym := c.table.get_type_symbol(arg.typ)
 | 
							arg_typ_sym := c.table.get_type_symbol(param.typ)
 | 
				
			||||||
		if f.is_variadic && typ.has_flag(.variadic) && call_expr.args.len - 1 > i {
 | 
							if f.is_variadic && typ.has_flag(.variadic) && call_expr.args.len - 1 > i {
 | 
				
			||||||
			c.error('when forwarding a variadic variable, it must be the final argument',
 | 
								c.error('when forwarding a variadic variable, it must be the final argument',
 | 
				
			||||||
				call_arg.pos)
 | 
									call_arg.pos)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		arg_share := arg.typ.share()
 | 
							arg_share := param.typ.share()
 | 
				
			||||||
		if arg_share == .shared_t && (c.locked_names.len > 0 || c.rlocked_names.len > 0) {
 | 
							if arg_share == .shared_t && (c.locked_names.len > 0 || c.rlocked_names.len > 0) {
 | 
				
			||||||
			c.error('function with `shared` arguments cannot be called inside `lock`/`rlock` block',
 | 
								c.error('function with `shared` arguments cannot be called inside `lock`/`rlock` block',
 | 
				
			||||||
				call_arg.pos)
 | 
									call_arg.pos)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if call_arg.is_mut && f.language == .v {
 | 
							if call_arg.is_mut && f.language == .v {
 | 
				
			||||||
			to_lock, pos := c.fail_if_immutable(call_arg.expr)
 | 
								to_lock, pos := c.fail_if_immutable(call_arg.expr)
 | 
				
			||||||
			if !arg.is_mut {
 | 
								if !param.is_mut {
 | 
				
			||||||
				tok := call_arg.share.str()
 | 
									tok := call_arg.share.str()
 | 
				
			||||||
				c.error('`$call_expr.name` parameter `$arg.name` is not `$tok`, `$tok` is not needed`',
 | 
									c.error('`$call_expr.name` parameter `$param.name` is not `$tok`, `$tok` is not needed`',
 | 
				
			||||||
					call_arg.expr.position())
 | 
										call_arg.expr.position())
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				if arg.typ.share() != call_arg.share {
 | 
									if param.typ.share() != call_arg.share {
 | 
				
			||||||
					c.error('wrong shared type', call_arg.expr.position())
 | 
										c.error('wrong shared type', call_arg.expr.position())
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if to_lock != '' && !arg.typ.has_flag(.shared_f) {
 | 
									if to_lock != '' && !param.typ.has_flag(.shared_f) {
 | 
				
			||||||
					c.error('$to_lock is `shared` and must be `lock`ed to be passed as `mut`',
 | 
										c.error('$to_lock is `shared` and must be `lock`ed to be passed as `mut`',
 | 
				
			||||||
						pos)
 | 
											pos)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if arg.is_mut {
 | 
								if param.is_mut {
 | 
				
			||||||
				tok := call_arg.share.str()
 | 
									tok := call_arg.share.str()
 | 
				
			||||||
				c.error('`$call_expr.name` parameter `$arg.name` is `$tok`, you need to provide `$tok` e.g. `$tok arg${
 | 
									c.error('`$call_expr.name` parameter `$param.name` is `$tok`, you need to provide `$tok` e.g. `$tok arg${
 | 
				
			||||||
					i + 1}`', call_arg.expr.position())
 | 
										i + 1}`', call_arg.expr.position())
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				c.fail_if_unreadable(call_arg.expr, typ, 'argument')
 | 
									c.fail_if_unreadable(call_arg.expr, typ, 'argument')
 | 
				
			||||||
| 
						 | 
					@ -2090,10 +2090,10 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// Handle expected interface
 | 
							// Handle expected interface
 | 
				
			||||||
		if arg_typ_sym.kind == .interface_ {
 | 
							if arg_typ_sym.kind == .interface_ {
 | 
				
			||||||
			c.type_implements(typ, arg.typ, call_arg.expr.position())
 | 
								c.type_implements(typ, param.typ, call_arg.expr.position())
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		c.check_expected_call_arg(typ, arg.typ, call_expr.language) or {
 | 
							c.check_expected_call_arg(typ, param.typ, call_expr.language) or {
 | 
				
			||||||
			// str method, allow type with str method if fn arg is string
 | 
								// str method, allow type with str method if fn arg is string
 | 
				
			||||||
			// Passing an int or a string array produces a c error here
 | 
								// Passing an int or a string array produces a c error here
 | 
				
			||||||
			// Deleting this condition results in propper V error messages
 | 
								// Deleting this condition results in propper V error messages
 | 
				
			||||||
| 
						 | 
					@ -2108,6 +2108,14 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			c.error('$err.msg in argument ${i + 1} to `$fn_name`', call_arg.pos)
 | 
								c.error('$err.msg in argument ${i + 1} to `$fn_name`', call_arg.pos)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							// Warn about automatic (de)referencing, which will be removed soon.
 | 
				
			||||||
 | 
							if f.language != .c && !c.inside_unsafe && typ.nr_muls() != param.typ.nr_muls()
 | 
				
			||||||
 | 
								&& !(call_arg.is_mut && param.is_mut)
 | 
				
			||||||
 | 
								&& param.typ !in [table.byteptr_type, table.charptr_type, table.voidptr_type] {
 | 
				
			||||||
 | 
								// sym := c.table.get_type_symbol(typ)
 | 
				
			||||||
 | 
								c.warn('automatic referencing/dereferencing is deprecated and will be removed soon (got: $typ.nr_muls() references, expected: $param.typ.nr_muls() references)',
 | 
				
			||||||
 | 
									call_arg.pos)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if f.generic_names.len != call_expr.generic_types.len {
 | 
						if f.generic_names.len != call_expr.generic_types.len {
 | 
				
			||||||
		// no type arguments given in call, attempt implicit instantiation
 | 
							// no type arguments given in call, attempt implicit instantiation
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -534,7 +534,7 @@ fn (mut g Gen) gen_str_for_struct(info table.Struct, styp string, str_fn_name st
 | 
				
			||||||
	g.auto_str_funcs.writeln('}')
 | 
						g.auto_str_funcs.writeln('}')
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn struct_auto_str_func(sym table.TypeSymbol, field_type table.Type, fn_name string, field_name string) string {
 | 
					fn struct_auto_str_func(sym &table.TypeSymbol, field_type table.Type, fn_name string, field_name string) string {
 | 
				
			||||||
	has_custom_str, expects_ptr, _ := sym.str_method_info()
 | 
						has_custom_str, expects_ptr, _ := sym.str_method_info()
 | 
				
			||||||
	if sym.kind == .enum_ {
 | 
						if sym.kind == .enum_ {
 | 
				
			||||||
		return '${fn_name}(it.${c_name(field_name)})'
 | 
							return '${fn_name}(it.${c_name(field_name)})'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue