-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check restriction on main actor before type checking (#4714)
Improve the error message for compiled code that contains illegal top-level declarations in the main program. c.f. https://forum.dfinity.org/t/misplaced-await-and-misplaced-async/34479
- Loading branch information
Showing
29 changed files
with
179 additions
and
121 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,38 @@ | ||
# M0141 | ||
|
||
This error indicates that the main actor or actor class has some leading or trailing declarations that are not just `import` declarations. | ||
|
||
The offending declarations should be moved into the body of the main actor or actor class. | ||
|
||
Here's an offending code example: | ||
|
||
```motoko | ||
import Int "mo:base/Int"; | ||
// illegal leading declarations before main actor | ||
type Point = (Int, Int); | ||
let origin : Point = (0, 0); | ||
actor { | ||
public func getOrigin() : async Point { origin }; | ||
} | ||
``` | ||
|
||
This is a possible correction of the code: | ||
|
||
```motoko | ||
import Int "mo:base/Int"; | ||
actor { | ||
// legal leading declarations within main actor | ||
type Point = (Int, Int); | ||
let origin : Point = (0, 0); | ||
public func getOrigin() : async Point { origin }; | ||
} | ||
``` | ||
|
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
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,12 @@ | ||
|
||
// bad leading decs | ||
type T1 = {}; | ||
type T2 = {}; | ||
|
||
actor Self { | ||
|
||
}; | ||
|
||
// bad trailing decs | ||
type U1 = {}; | ||
type U2 = {}; |
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,4 @@ | ||
bad-actor.mo:3.1-4.13: type error [M0141], move these declarations into the body of the main actor or actor class | ||
bad-actor.mo:11.1-12.13: type error [M0141], move these declarations into the body of the main actor or actor class | ||
bad-actor.mo:6.1-8.2: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version and flag -ref-system-api.) |
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 @@ | ||
Return code 1 |
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,4 @@ | ||
bad-actor.mo:3.1-4.13: type error [M0141], move these declarations into the body of the main actor or actor class | ||
bad-actor.mo:11.1-12.13: type error [M0141], move these declarations into the body of the main actor or actor class | ||
bad-actor.mo:6.1-8.2: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version.) |
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 @@ | ||
Return code 1 |
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,2 +1,3 @@ | ||
issue-1938-b.mo:2.1-2.9: type error [M0038], misplaced await | ||
issue-1938-b.mo:2.1-2.9: type error [M0037], misplaced async expression; try enclosing in an async function | ||
issue-1938-b.mo:1.1-1.3: type error [M0141], move these declarations into the body of the main actor or actor class | ||
issue-1938-b.mo:2.1-2.9: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version and flag -ref-system-api.) |
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,2 +1,3 @@ | ||
issue-1938-b.mo:2.1-2.9: type error [M0038], misplaced await | ||
issue-1938-b.mo:2.1-2.9: type error [M0037], misplaced async expression; try enclosing in an async function | ||
issue-1938-b.mo:1.1-1.3: type error [M0141], move these declarations into the body of the main actor or actor class | ||
issue-1938-b.mo:2.1-2.9: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version.) |
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,2 +1,3 @@ | ||
issue-1938-c.mo:2.1-2.11: type error [M0038], misplaced await | ||
issue-1938-c.mo:2.1-2.11: type error [M0037], misplaced async expression; try enclosing in an async function | ||
issue-1938-c.mo:1.1-1.3: type error [M0141], move these declarations into the body of the main actor or actor class | ||
issue-1938-c.mo:2.1-2.11: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version and flag -ref-system-api.) |
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,2 +1,3 @@ | ||
issue-1938-c.mo:2.1-2.11: type error [M0038], misplaced await | ||
issue-1938-c.mo:2.1-2.11: type error [M0037], misplaced async expression; try enclosing in an async function | ||
issue-1938-c.mo:1.1-1.3: type error [M0141], move these declarations into the body of the main actor or actor class | ||
issue-1938-c.mo:2.1-2.11: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version.) |
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,2 +1,3 @@ | ||
issue-1938-d.mo:1.1-1.3: type error [M0141], move these declarations into the body of the main actor or actor class | ||
issue-1938-d.mo:2.1-2.19: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version and flag -ref-system-api.) |
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,2 +1,3 @@ | ||
issue-1938-d.mo:1.1-1.3: type error [M0141], move these declarations into the body of the main actor or actor class | ||
issue-1938-d.mo:2.1-2.19: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version.) |
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,2 +1,3 @@ | ||
issue-1938.mo:2.1-2.11: type error [M0038], misplaced await | ||
issue-1938.mo:2.1-2.11: type error [M0037], misplaced async expression; try enclosing in an async function | ||
issue-1938.mo:1.1-1.13: type error [M0141], move these declarations into the body of the main actor or actor class | ||
issue-1938.mo:2.1-2.11: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version and flag -ref-system-api.) |
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,2 +1,3 @@ | ||
issue-1938.mo:2.1-2.11: type error [M0038], misplaced await | ||
issue-1938.mo:2.1-2.11: type error [M0037], misplaced async expression; try enclosing in an async function | ||
issue-1938.mo:1.1-1.13: type error [M0141], move these declarations into the body of the main actor or actor class | ||
issue-1938.mo:2.1-2.11: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version.) |
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,3 +1,2 @@ | ||
unavailable-constructor.mo:1.36-1.37: type error [M0056], variable C is in scope but not available in compiled code | ||
unavailable-constructor.mo:5.17-5.18: type error [M0056], variable C is in scope but not available in compiled code | ||
unavailable-constructor.mo:8.31-8.32: type error [M0056], variable C is in scope but not available in compiled code | ||
unavailable-constructor.mo:3.17-3.18: type error [M0056], variable C is in scope but not available in compiled code | ||
unavailable-constructor.mo:6.31-6.32: type error [M0056], variable C is in scope but not available in compiled code |
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,3 +1,2 @@ | ||
unavailable-constructor.mo:1.36-1.37: type error [M0056], variable C is in scope but not available in compiled code | ||
unavailable-constructor.mo:5.17-5.18: type error [M0056], variable C is in scope but not available in compiled code | ||
unavailable-constructor.mo:8.31-8.32: type error [M0056], variable C is in scope but not available in compiled code | ||
unavailable-constructor.mo:3.17-3.18: type error [M0056], variable C is in scope but not available in compiled code | ||
unavailable-constructor.mo:6.31-6.32: type error [M0056], variable C is in scope but not available in compiled code |
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,2 +1 @@ | ||
unavailable-constructor.mo:1.6-1.7: warning [M0194], unused identifier f (delete or rename to wildcard `_` or `_f`) | ||
unavailable-constructor.mo:7.17-7.21: warning [M0194], unused identifier ctxt (delete or rename to wildcard `_` or `_ctxt`) | ||
unavailable-constructor.mo:5.17-5.21: warning [M0194], unused identifier ctxt (delete or rename to wildcard `_` or `_ctxt`) |
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,4 +1,3 @@ | ||
unsupported-more.mo:2.1-5.2: type error [M0038], misplaced await | ||
unsupported-more.mo:2.1-5.2: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported-more.mo:8.1-8.25: type error [M0038], misplaced await | ||
unsupported-more.mo:8.1-8.25: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported-more.mo:8.1-8.25: type error [M0141], move these declarations into the body of the main actor or actor class | ||
unsupported-more.mo:2.1-5.2: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version and flag -ref-system-api.) |
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,4 +1,3 @@ | ||
unsupported-more.mo:2.1-5.2: type error [M0038], misplaced await | ||
unsupported-more.mo:2.1-5.2: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported-more.mo:8.1-8.25: type error [M0038], misplaced await | ||
unsupported-more.mo:8.1-8.25: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported-more.mo:8.1-8.25: type error [M0141], move these declarations into the body of the main actor or actor class | ||
unsupported-more.mo:2.1-5.2: type error [M0141], an actor or actor class must be the only non-imported declaration in a program | ||
(This is a limitation of the current version.) |
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,24 +1,16 @@ | ||
unsupported.mo:2.1-33.2: type error [M0038], misplaced await | ||
unsupported.mo:2.1-33.2: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported.mo:4.14-4.50: type error [M0126], a shared function cannot be private | ||
unsupported.mo:36.36-36.39: type error [M0077], a shared function is only allowed as a public field of an actor | ||
(This is a limitation of the current version and flag -ref-system-api.) | ||
unsupported.mo:36.26-36.29: type error [M0077], a shared function is only allowed as a public field of an actor | ||
unsupported.mo:50.11-50.43: type error [M0139], inner actor classes are not supported yet; any actor class must come last in your program | ||
(This is a limitation of the current version and flag -ref-system-api.) | ||
unsupported.mo:50.3-50.35: type error [M0139], inner actor classes are not supported yet; any actor class must come last in your program | ||
unsupported.mo:54.11-54.50: type error [M0139], inner actor classes are not supported yet; any actor class must come last in your program | ||
(This is a limitation of the current version and flag -ref-system-api.) | ||
unsupported.mo:54.3-54.42: type error [M0139], inner actor classes are not supported yet; any actor class must come last in your program | ||
unsupported.mo:58.53-58.61: type error [M0069], non-toplevel actor; an actor can only be declared at the toplevel of a program | ||
(This is a limitation of the current version and flag -ref-system-api.) | ||
unsupported.mo:58.45-58.53: type error [M0038], misplaced await | ||
unsupported.mo:58.45-58.53: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported.mo:58.45-58.53: type error [M0069], non-toplevel actor; an actor can only be declared at the toplevel of a program | ||
unsupported.mo:62.47-62.55: type error [M0069], non-toplevel actor; an actor can only be declared at the toplevel of a program | ||
(This is a limitation of the current version and flag -ref-system-api.) | ||
unsupported.mo:62.39-62.47: type error [M0038], misplaced await | ||
unsupported.mo:62.39-62.47: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported.mo:62.39-62.47: type error [M0069], non-toplevel actor; an actor can only be declared at the toplevel of a program | ||
unsupported.mo:72.44-72.47: type error [M0077], a shared function is only allowed as a public field of an actor | ||
(This is a limitation of the current version and flag -ref-system-api.) | ||
unsupported.mo:66.1-66.25: type error [M0038], misplaced await | ||
unsupported.mo:66.1-66.25: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported.mo:72.34-72.37: type error [M0077], a shared function is only allowed as a public field of an actor | ||
unsupported.mo:73.44-73.47: type error [M0077], a shared function is only allowed as a public field of an actor | ||
(This is a limitation of the current version and flag -ref-system-api.) | ||
unsupported.mo:73.27-73.30: type error [M0077], a shared function is only allowed as a public field of an actor | ||
unsupported.mo:4.14-4.50: type error [M0126], a shared function cannot be private | ||
(This is a limitation of the current version and flag -ref-system-api.) |
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,24 +1,16 @@ | ||
unsupported.mo:2.1-33.2: type error [M0038], misplaced await | ||
unsupported.mo:2.1-33.2: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported.mo:4.14-4.50: type error [M0126], a shared function cannot be private | ||
unsupported.mo:36.36-36.39: type error [M0077], a shared function is only allowed as a public field of an actor | ||
(This is a limitation of the current version.) | ||
unsupported.mo:36.26-36.29: type error [M0077], a shared function is only allowed as a public field of an actor | ||
unsupported.mo:50.11-50.43: type error [M0139], inner actor classes are not supported yet; any actor class must come last in your program | ||
(This is a limitation of the current version.) | ||
unsupported.mo:50.3-50.35: type error [M0139], inner actor classes are not supported yet; any actor class must come last in your program | ||
unsupported.mo:54.11-54.50: type error [M0139], inner actor classes are not supported yet; any actor class must come last in your program | ||
(This is a limitation of the current version.) | ||
unsupported.mo:54.3-54.42: type error [M0139], inner actor classes are not supported yet; any actor class must come last in your program | ||
unsupported.mo:58.53-58.61: type error [M0069], non-toplevel actor; an actor can only be declared at the toplevel of a program | ||
(This is a limitation of the current version.) | ||
unsupported.mo:58.45-58.53: type error [M0038], misplaced await | ||
unsupported.mo:58.45-58.53: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported.mo:58.45-58.53: type error [M0069], non-toplevel actor; an actor can only be declared at the toplevel of a program | ||
unsupported.mo:62.47-62.55: type error [M0069], non-toplevel actor; an actor can only be declared at the toplevel of a program | ||
(This is a limitation of the current version.) | ||
unsupported.mo:62.39-62.47: type error [M0038], misplaced await | ||
unsupported.mo:62.39-62.47: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported.mo:62.39-62.47: type error [M0069], non-toplevel actor; an actor can only be declared at the toplevel of a program | ||
unsupported.mo:72.44-72.47: type error [M0077], a shared function is only allowed as a public field of an actor | ||
(This is a limitation of the current version.) | ||
unsupported.mo:66.1-66.25: type error [M0038], misplaced await | ||
unsupported.mo:66.1-66.25: type error [M0037], misplaced async expression; try enclosing in an async function | ||
unsupported.mo:72.34-72.37: type error [M0077], a shared function is only allowed as a public field of an actor | ||
unsupported.mo:73.44-73.47: type error [M0077], a shared function is only allowed as a public field of an actor | ||
(This is a limitation of the current version.) | ||
unsupported.mo:73.27-73.30: type error [M0077], a shared function is only allowed as a public field of an actor | ||
unsupported.mo:4.14-4.50: type error [M0126], a shared function cannot be private | ||
(This is a limitation of the current version.) |
Oops, something went wrong.