Skip to content

Commit

Permalink
fix(rivet/resolver): avoid clash of name of fields and symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 23, 2023
1 parent ced088d commit 5da61ed
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 14 deletions.
1 change: 0 additions & 1 deletion cmd/src/tools/cmd_fmt.ri
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import std/flag;
import std/console;
import std/fs.Directory;

import rivet;
import rivet/ast;
import rivet/fmt;
import rivet/prefs;
Expand Down
16 changes: 13 additions & 3 deletions lib/rivet/src/resolver/decls.ri
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,19 @@ extend Resolver {
}
self.resolve_decls(extend_decl.decls);
},
.Field(mut field_decl) -> if self.resolve_type(field_decl.type)
&& field_decl.has_def_expr {
self.resolve_expr(field_decl.def_expr);
.Field(mut field_decl) -> if self.resolve_type(field_decl.type) {
if field_decl.has_def_expr {
self.resolve_expr(field_decl.def_expr);
}
if sym := self.self_sym.scope.find(field_decl.name) {
report.error(
"{} `{}` has field and {} named `{}`".fmt(
self.self_sym.type_of(), self.self_sym.name, sym.type_of(), field_decl.name
),
field_decl.pos
);
continue;
}
},
.Func(mut func_decl) -> {
if func_decl.is_method {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/src/backtrace/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import core;

#[inline]
pub func print(frames_to_skip: int32 = 0) {
pub func print(frames_to_skip: int32 := 0) {
core.bt_print(frames_to_skip);
}
10 changes: 5 additions & 5 deletions lib/std/src/dynlib/mod.ri → lib/std/src/dynlib/mod.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

import c/libc;

pub var sharedLibExtension := get_shared_library_extension();
pub var shared_lib_extension := get_shared_library_extension();

/// Returns a library name with the operating system specific extension for shared
/// libraries.
#[inline]
pub func library_name(libname: string) -> string {
return if libname.ends_with(sharedLibExtension) {
return if libname.ends_with(shared_lib_extension) {
libname
} else {
libname.concat(sharedLibExtension)
libname.concat(shared_lib_extension)
};
}

Expand All @@ -39,8 +39,8 @@ pub struct CannotLoadLibraryError < Throwable {
}
}

pub func load(path: string, global_symbols: bool = false) -> !Library {
flags := if global_symbols { libc.RTLD_NOW | libc.RTLD_GLOBAL } else { libc.RTLD_NOW };
pub func load(path: string, global_symbols: bool := false) -> !Library {
flags: int32 := if global_symbols { libc.RTLD_NOW | libc.RTLD_GLOBAL } else { libc.RTLD_NOW };
if ptr := unsafe { libc.dlopen(path.ptr, flags) } {
return Library(path, ptr);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/std/src/flag/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct FlagParser {
mut application_description: string;
mut args_description: string;
/// Whether passing undescribed arguments is allowed.
mut allow_unknown_args: bool;
mut allow_unknown_args_: bool;
/// When set, --help will display all the collected footers at the bottom.
mut footers: []string;

Expand Down Expand Up @@ -184,7 +184,7 @@ pub struct FlagParser {
/// to fail.
#[inline]
pub func allow_unknown_args(mut self) {
self.allow_unknown_args = true;
self.allow_unknown_args_ = true;
}

/// Returns an option with the bool value of the given command line flag, named `name`.
Expand Down Expand Up @@ -325,7 +325,7 @@ pub struct FlagParser {
pub func finalize(mut self) -> ![]string {
self.handle_builtin_options();
mut remaining := self.args.clone();
if !self.allow_unknown_args {
if !self.allow_unknown_args_ {
for arg in remaining {
if (arg.len >= 2 && arg.substr(end: 2) == "--")
|| (arg.len == 2 && arg[0] == '-') {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/src/math/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub const LN10: float64 := 2.302585092994045684017991454684364207601101488628772
pub const LOG10_E: float64 := 1.0 / LN10;

/// Returns the number of digits in the number passed.
pub func count_digits(number: int64) -> int32 {
pub func count_digits(number: int) -> int {
if number == 0 {
return 1;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/invalid/clash_of_name_of_fields_and_symbols.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tests/invalid/clash_of_name_of_fields_and_symbols.ri:2:5: error: struct `Xyz` has field and function named `a`
2 | a: int;
| ^~~~~~
rivet: error: could not compile module `clash_of_name_of_fields_and_symbols`, aborting due to previous error
5 changes: 5 additions & 0 deletions tests/invalid/clash_of_name_of_fields_and_symbols.ri
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct Xyz {
a: int;

func a() {}
}

0 comments on commit 5da61ed

Please sign in to comment.