-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: bound subtyping depth to avoid reliance on unpredictable stac…
…k overflow (#4798) * repro for subtyping loop due to polymorhic recursion * Update test/fail/polyrec.mo * Update test/fail/polyrec.mo Co-authored-by: Gabor Greif <[email protected]> * hack subtyping to accept polyrec.mo by treating equivalent instanstations of the same constructor as related by subtyping * add bound to subtyping instead of relying on unpredictable and expensive OOM/stackoverflow * tidy * missin file? * turn overflow into error (WIP) * add error code desc; use dedicated exception Undecided * Update src/lang_utils/error_codes/M0200.md * check issue-3057 * Update test/fail/issue-3057.mo --------- Co-authored-by: Gabor Greif <[email protected]>
- Loading branch information
Showing
12 changed files
with
175 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# M0200 | ||
|
||
This error means that the compiler encountered a subtyping, equivalence or constructor equivalence problem that it cannot decide is true or false in a timely manner. | ||
|
||
This is due to a limitation of the type system and may require you to rewrite | ||
some of your code to avoid the problem. | ||
|
||
The most like cause is a recursive type or class whose definition involves | ||
instantiating the type or class with nested type parameters. | ||
|
||
For example, this definition of `Box<T>` | ||
|
||
``` motoko | ||
class Box<T>(v : T) { | ||
public let value = t; | ||
public func map<R>(f : T -> R) : Box<R> { | ||
Box<R>(f t) | ||
}; | ||
} | ||
``` | ||
is problematic because `Box<R>` is instantiated at `R`, an inner type parameter, while | ||
|
||
``` motoko | ||
class Box<T>(v : T) { | ||
public let value = v; | ||
public func map(f : T -> T) : Box<T> { | ||
Box<T>(f value) | ||
}; | ||
} | ||
``` | ||
is accepted (but also less useful). | ||
|
||
Another workaround is to define the problematic method as a separate | ||
function, outside of the class: | ||
|
||
``` motoko | ||
class Box<T>(v : T) { | ||
public let value = v | ||
}; | ||
func map<T, R>(b : Box<T>, f : T -> R) : Box<R> { | ||
Box<R>(f(b.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
Oops, something went wrong.