-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for types aliasing uni T values
When lowering to MIR, we check for types that aren't fully inferred. This commit extends this check to also check for `uni ref T` and `uni mut T` values stored inside other types, producing an error when encountering such types. This ensures that one can't violate the uniqueness constraints through e.g. a generic method, without complicating the type system (e.g. by adding a `T: ref` bound). This fixes #713. Changelog: fixed
- Loading branch information
1 parent
45e116b
commit 26070da
Showing
4 changed files
with
127 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class User { | ||
let @name: String | ||
} | ||
|
||
class Box[T] { | ||
let @value: Option[T] | ||
let @borrow: Option[ref T] | ||
|
||
fn mut store(value: T) { | ||
@value = Option.Some(value) | ||
} | ||
} | ||
|
||
fn example1 { | ||
let a = [recover User('Alice')] | ||
|
||
a.opt(0) | ||
} | ||
|
||
fn example2 { | ||
let a = recover User('Alice') | ||
let b = Option.Some(a) | ||
|
||
b.as_ref | ||
} | ||
|
||
fn example3 { | ||
let a = recover User('Alice') | ||
|
||
Box(value: Option.Some(a), borrow: Option.None) | ||
} | ||
|
||
fn example4 { | ||
let a = recover User('Alice') | ||
let b = Box(value: Option.None, borrow: Option.None) | ||
|
||
b.value = Option.Some(a) | ||
} | ||
|
||
fn example5 { | ||
let a = recover User('Alice') | ||
let b = Box(value: Option.None, borrow: Option.None) | ||
|
||
b.store(a) | ||
} | ||
|
||
fn example6 { | ||
let a = recover User('Alice') | ||
|
||
ref a | ||
} | ||
|
||
# uni_aliasing.inko:17:3 error(invalid-type): the type of this expression ('Option[uni ref User]') is invalid because it contains an 'uni ref T' or 'uni mut T' value | ||
# uni_aliasing.inko:24:3 error(invalid-type): the type of this expression ('Option[uni ref User]') is invalid because it contains an 'uni ref T' or 'uni mut T' value | ||
# uni_aliasing.inko:30:38 error(invalid-type): the type of this expression ('Option[uni ref User]') is invalid because it contains an 'uni ref T' or 'uni mut T' value | ||
# uni_aliasing.inko:35:43 error(invalid-type): the type of this expression ('Option[uni ref User]') is invalid because it contains an 'uni ref T' or 'uni mut T' value | ||
# uni_aliasing.inko:42:43 error(invalid-type): the type of this expression ('Option[uni ref User]') is invalid because it contains an 'uni ref T' or 'uni mut T' value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters