Skip to content

Commit 632e4f6

Browse files
committed
Make sure Binder panics if it tries to bind to a dotted identifier
1 parent 95fa3ae commit 632e4f6

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

poniescript-core/src/binder.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,31 +171,32 @@ impl<'db> Binder<'db> {
171171
return Some(Expr::mk_variable(unbound.location.clone(), v));
172172
}
173173
ScopeEntry::Fun(fun) => {
174-
175-
176-
// The object for the UnboundFuncapture should be:
177-
// - Its current associated object, if it has one; otherwise:
178-
// - self.get_selfval()
174+
// The Binder is not equipped to handle ANY name resolution
175+
// on a bound object. That MUST wait until type checking.
176+
//
177+
// As such, panic if we ever attempt this. This is even wrong
178+
// in an LSP context; it is literally a bug if we get here,
179+
// not just an improperly handled case.
179180
//
180-
// This is because an unboundfuncapture with no associated
181-
// object is still 'floating' and may need to be bound to
182-
// its class scope. But if it's called on an object, there
183-
// is no world in which we should overwrite that object.. (?)
181+
// This also means that we *always* call self.get_selfval(),
182+
// as the object is always already None. We used to only
183+
// call self.get_selfval() if the object was None, but
184+
// this extra logic is unnecessary, because the object should
185+
// ALWAYS be None.
186+
if unbound.object.is_some() {
187+
panic!("ICE: Binder tried to resolve_unbound_funcapture on a bound expression. This should never happen.");
188+
}
184189

185190
log::trace!("resolved unbound funcapture '{}' to fun in scope '{}'; self_val: {}",
186191
self.db.get(unbound.identifier.lexeme),
187192
checker.buffer,
188193
checker.self_val);
189194

190195
let self_val = checker.self_val;
191-
192-
let object = match unbound.object {
193-
Some(obj) => Some(obj),
194-
None => self.get_selfval(ast, unbound.location.clone(), self_val)
195-
};
196+
let self_val = self.get_selfval(ast, unbound.location.clone(), self_val);
196197

197198
return Some(Expr::mk_funcapture(unbound.location.clone(), unbound.identifier.location.clone(), fun, self.db.types.unassigned,
198-
object))
199+
self_val))
199200
}
200201
ScopeEntry::Class(_) => {
201202
self.db.report_error(Error::simple(

0 commit comments

Comments
 (0)