Skip to content

Commit 6c5312b

Browse files
committed
feat(rivet/resolver+rivetc.resolver): allow use of static functions without using Self.
1 parent 2cedfa2 commit 6c5312b

File tree

3 files changed

+16
-34
lines changed

3 files changed

+16
-34
lines changed

lib/rivet/src/resolver/exprs.ri

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,6 @@ extend Resolver {
270270
} else if self.self_sym_is_set {
271271
if sym := self.self_sym.scope.find(ident.name) {
272272
if !(sym is ast.TypeSym(type_sym) && type_sym.info is .Placeholder) {
273-
if sym is ast.Func {
274-
mut err := report.error_builder(
275-
"cannot find `{}` in this scope".fmt(ident.name), ident.pos
276-
);
277-
err.add_help("use `Self.{}()` instead", sym.name);
278-
err.emit();
279-
return;
280-
}
281273
ident.found = true;
282274
ident.is_sym = true;
283275
ident.sym = sym;

lib/std/src/fs/Path.c.ri

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct Path {
5656
/// Returns `true` if `path` is a file.
5757
#[inline]
5858
pub func is_file(path: string) -> bool {
59-
return Self.exists(path) && !Self.is_directory(path);
59+
return exists(path) && !is_directory(path);
6060
}
6161

6262
/// Returns `true` if `path` is absolute.
@@ -142,7 +142,7 @@ pub struct Path {
142142
/// Files that end with `.`, or that start with `.` and have no other `.` in their
143143
/// name, are considered to have no extension.
144144
pub func extension(path: string) -> string {
145-
filename := Self.file_name(path);
145+
filename := file_name(path);
146146
index := filename.last_index_of_byte('.') ?? return "";
147147
return if index == 0 || index + 1 >= filename.len {
148148
""
@@ -164,7 +164,7 @@ pub struct Path {
164164
mut have_abs := false;
165165
mut max_size: uint := 0;
166166
for i, p in paths {
167-
if Self.is_absolute(p) {
167+
if is_absolute(p) {
168168
first_index = i;
169169
have_abs = true;
170170
max_size = 0;
@@ -234,8 +234,8 @@ pub struct Path {
234234
/// resolve to the same path (after calling `resolve` on each), a zero-length
235235
/// string is returned.
236236
pub func relative(from_: string, to: string) -> !string {
237-
_ = Self.resolve(from_)!;
238-
_ = Self.resolve(to)!;
237+
_ = resolve(from_)!;
238+
_ = resolve(to)!;
239239
mut from_it := from_.tokenize(SEPARATOR);
240240
mut to_it := to.tokenize(SEPARATOR);
241241
while {
@@ -315,8 +315,8 @@ pub struct Path {
315315
if this_path.is_empty() {
316316
continue;
317317
}
318-
prev_sep := Self.is_separator(prev_path[prev_path.len - 1]);
319-
this_sep := Self.is_separator(this_path[0]);
318+
prev_sep := is_separator(prev_path[prev_path.len - 1]);
319+
this_sep := is_separator(this_path[0]);
320320
sum += (!prev_sep && !this_sep).to_uint();
321321
sum += if prev_sep && this_sep { this_path.len - 1 } else { this_path.len };
322322
prev_path = this_path;
@@ -339,8 +339,8 @@ pub struct Path {
339339
if this_path.is_empty() {
340340
continue;
341341
}
342-
prev_sep := Self.is_separator(prev_path[prev_path.len - 1]);
343-
this_sep := Self.is_separator(this_path[0]);
342+
prev_sep := is_separator(prev_path[prev_path.len - 1]);
343+
this_sep := is_separator(this_path[0]);
344344
if !prev_sep && !this_sep {
345345
unsafe {
346346
buf[buf_index] = SEPARATOR;
@@ -369,13 +369,13 @@ pub struct Path {
369369
if path.is_empty() {
370370
return cwd;
371371
}
372-
rpath := Self.resolve(path)!;
372+
rpath := resolve(path)!;
373373
if rpath == "." {
374374
return cwd;
375375
}
376-
if Self.is_absolute(rpath) {
376+
if is_absolute(rpath) {
377377
return rpath;
378378
}
379-
return Self.resolve(Self.join(cwd, rpath)!)!;
379+
return resolve(join(cwd, rpath)!)!;
380380
}
381381
}

rivetc/src/resolver.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -413,21 +413,11 @@ def resolve_ident(self, ident):
413413
ident.is_sym = True
414414
elif self.self_sym:
415415
if s := self.self_sym.find(ident.name):
416-
if isinstance(
416+
if not (isinstance(
417417
s, sym.Type
418-
) and s.kind == sym.TypeKind.Placeholder:
419-
report.error(
420-
f"cannot find `{ident.name}` in this scope", ident.pos
421-
)
422-
ident.not_found = True
423-
elif isinstance(s, sym.Func):
424-
report.error(
425-
f"cannot find `{ident.name}` in this scope", ident.pos
426-
)
427-
report.help(f"use `Self.{s.name}()` instead")
428-
ident.not_found = True
429-
ident.sym = s
430-
ident.is_sym = True
418+
) and s.kind == sym.TypeKind.Placeholder):
419+
ident.sym = s
420+
ident.is_sym = True
431421
if ident.sym == None and ident.obj == None:
432422
report.error(f"cannot find `{ident.name}` in this scope", ident.pos)
433423
ident.not_found = True

0 commit comments

Comments
 (0)