Skip to content

Commit

Permalink
WIP: type hack
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickpeterse committed Nov 22, 2023
1 parent 86ed3f4 commit ad83452
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
8 changes: 7 additions & 1 deletion compiler/src/type_check/define_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,13 @@ impl<'a> ImplementTraits<'a> {
&bounds,
);

let rules = Rules::default();
let mut rules = Rules::default();

// TODO: remove
if self.file().ends_with("Downloads/test.inko") {
rules.type_parameters_as_owned = true;
}

let mut definer =
DefineTypeSignature::new(self.state, self.module, &scope, rules);

Expand Down
8 changes: 7 additions & 1 deletion compiler/src/type_check/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,13 +1281,19 @@ impl<'a> ImplementTraitMethods<'a> {
self_type,
);

let rules = Rules {
let mut rules = Rules {
allow_private_types: class_instance
.instance_of()
.is_private(self.db())
|| method.is_private(self.db()),
..Default::default()
};

// TODO: remove
if self.file().ends_with("Downloads/test.inko") {
rules.type_parameters_as_owned = true;
}

let receiver = receiver_type(self.db(), self_type, node.kind);

method.set_receiver(self.db_mut(), receiver);
Expand Down
16 changes: 10 additions & 6 deletions types/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ impl<'a> TypeResolver<'a> {
self.cached.insert(value, value);

let resolved = match value {
TypeRef::Owned(id) | TypeRef::Infer(id) => {
match self.resolve_type_id(id) {
Either::Left(res) => TypeRef::Owned(res),
Either::Right(typ) => typ,
}
}
TypeRef::Owned(id) => match self.resolve_type_id(id) {
Either::Left(res) => TypeRef::Owned(res),
// TODO: this is to simulate forcing owned type parameter
// values to also be owned.
Either::Right(typ) => typ.as_owned(self.db),
},
TypeRef::Infer(id) => match self.resolve_type_id(id) {
Either::Left(res) => TypeRef::Owned(res),
Either::Right(typ) => typ,
},
TypeRef::Pointer(id) => match self.resolve_type_id(id) {
Either::Left(res) => TypeRef::Pointer(res),
Either::Right(
Expand Down

0 comments on commit ad83452

Please sign in to comment.