-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into luc/rust-upgrade
- Loading branch information
Showing
19 changed files
with
174 additions
and
135 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
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
9 changes: 6 additions & 3 deletions
9
src/lang_utils/error_codes/M0003.adoc → src/lang_utils/error_codes/M0003.md
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
= M0003 | ||
# M0003 | ||
|
||
This error means that a module tried to import itself. | ||
|
||
Erroneous code example (file is called `Self.mo`): | ||
|
||
import S "./Self"; // import error, file Self.mo must not depend on itself | ||
module { } | ||
```motoko | ||
import S "./Self"; // import error, file Self.mo must not depend on itself | ||
module { ... } | ||
``` | ||
|
||
If you encounter this error you should probably remove the offending import. |
This file was deleted.
Oops, something went wrong.
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,38 @@ | ||
# M0137 | ||
|
||
This error means that you declared a type or class that explicitly or implicitly references | ||
an outer type parameter. | ||
|
||
Erroneous code examples: | ||
|
||
```motoko | ||
class C<T>(){ | ||
type U = T; // type U mentions parameter T of class C | ||
}; | ||
``` | ||
|
||
```motoko | ||
class D<T>(){ | ||
class E(x : T) { | ||
public let y : T = x; // class E mentions parameter T of class D in a field | ||
}; | ||
} | ||
``` | ||
|
||
To avoid this error, try parameterizing the inner types. | ||
|
||
```motoko | ||
class C<T>(){ | ||
type U<T1> = T1; | ||
}; | ||
``` | ||
|
||
```motoko | ||
class D<T>(){ | ||
class E<T1>(x : T1) { | ||
public let y : T1 = x; | ||
}; | ||
} | ||
``` | ||
|
||
This is a temporary restriction of Motoko that we hope to remove in future. |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
# M0149 | ||
|
||
This error means that you supplied an immutable record field (declared without `var`), where a mutable record field (specified with `var`), was expected. | ||
|
||
Erroneous code example: | ||
|
||
```motoko | ||
{ count = 0 } : { var count : Nat } | ||
``` | ||
|
||
If you encounter this error, you should probably insert the `var` keyword: | ||
|
||
```motoko | ||
{ var count = 1 } : { var count : Nat } | ||
``` |
12 changes: 7 additions & 5 deletions
12
src/lang_utils/error_codes/M0150.adoc → src/lang_utils/error_codes/M0150.md
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
= M0150 | ||
# M0150 | ||
|
||
This error means you supplied a mutable record field (declared with `var`) where an immutable record field (specified without `var`) was expected. | ||
|
||
Erroneous code example: | ||
|
||
|
||
{ var name = "Fred" } : { name : Text } | ||
|
||
```motoko | ||
{ var name = "Fred" } : { name : Text } | ||
``` | ||
|
||
If you encounter this error, you should probably omit `var`: | ||
|
||
{ name = "Fred" } : { name : Text } | ||
```motoko | ||
{ name = "Fred" } : { name : Text } | ||
``` |
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
# M0151 | ||
|
||
This error means that a object literal is missing some fields, maybe because of a typo. | ||
|
||
Erroneous code examples: | ||
|
||
```motoko | ||
{ first_name = "Fred" } : { firstName : Text } | ||
{ firstName = "Fred" } : { firstName : Text; lastName : Text } | ||
``` | ||
|
||
If you encounter this error, you need to add the missing field name to the | ||
object literal. | ||
|
||
```motoko | ||
{ firstName = "Fred" } : { firstName : Text } | ||
{ firstName = "Fred"; lastName = "Flintstone" } : { firstName : Text; lastName : Text } | ||
``` |
8 changes: 4 additions & 4 deletions
8
src/lang_utils/error_codes/M0153.adoc → src/lang_utils/error_codes/M0153.md
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
12 changes: 7 additions & 5 deletions
12
src/lang_utils/error_codes/M0154.adoc → src/lang_utils/error_codes/M0154.md
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
= M0154 | ||
# M0154 | ||
|
||
You are using a field (typically a module field) that has a deprecation annotation | ||
attached to its definition, e.g. | ||
|
||
module SomeModule { | ||
```motoko | ||
module SomeModule { | ||
/// @deprecated The foo function is deprecated and will be removed next release | ||
public func foo() {} | ||
/// @deprecated The foo function is deprecated and will be removed next release | ||
public func foo() {} | ||
} | ||
} | ||
``` | ||
|
||
The warning should include an explanation provided by the author of that code. |
45 changes: 23 additions & 22 deletions
45
src/lang_utils/error_codes/M0155.adoc → src/lang_utils/error_codes/M0155.md
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 |
---|---|---|
@@ -1,48 +1,49 @@ | ||
= M0155 | ||
# M0155 | ||
|
||
This warning indicates that the type of a subtraction operation had to be deduced from its operands and was inferred to be `Nat`. | ||
That implies that it traps when the result is negative, which may be unintentional. | ||
|
||
Offending code examples: | ||
|
||
``` | ||
func f(n : Nat) { | ||
if (n < 10) { return }; | ||
let m = 2 * (n - 1); | ||
}; | ||
```motoko | ||
func f(n : Nat) { | ||
if (n < 10) { return }; | ||
let m = 2 * (n - 1); | ||
}; | ||
func g(n : Nat) { | ||
if (n - 1 < 10) { return }; | ||
}; | ||
func g(n : Nat) { | ||
if (n - 1 < 10) { return }; | ||
}; | ||
``` | ||
|
||
If the subtraction was indeed intended to have a `Nat` result, you can let the compiler know by annotating the intended type explicitly: | ||
|
||
``` | ||
func f(n : Nat) { | ||
let m : Nat = 2 * (n - 1); | ||
}; | ||
```motoko | ||
func f(n : Nat) { | ||
let m : Nat = 2 * (n - 1); | ||
}; | ||
``` | ||
|
||
If the intended type was `Int`, however, you can either annotate it as such: | ||
|
||
``` | ||
func f(n : Nat) { | ||
let m : Int = 2 * (n - 1); | ||
}; | ||
func f(n : Nat) { | ||
let m : Int = 2 * (n - 1); | ||
}; | ||
``` | ||
|
||
Or you can insert a sign operator `+`, which also forces the expression to be of type `Int`: | ||
|
||
``` | ||
func f(n : Nat) { | ||
let m = 2 * (+n - 1); | ||
}; | ||
func f(n : Nat) { | ||
let m = 2 * (+n - 1); | ||
}; | ||
``` | ||
|
||
This latter possibility is particularly convenient in the case of comparisons, because it is always okay to perform them at type `Int`: | ||
|
||
``` | ||
func g(n : Nat) { | ||
if (+n - 1 < 10) { return }; | ||
}; | ||
func g(n : Nat) { | ||
if (+n - 1 < 10) { return }; | ||
}; | ||
``` |
10 changes: 7 additions & 3 deletions
10
src/lang_utils/error_codes/M0156.adoc → src/lang_utils/error_codes/M0156.md
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.