diff --git a/src/lang_utils/error_codes.ml b/src/lang_utils/error_codes.ml index eab5b5b6f70..16cbd291704 100644 --- a/src/lang_utils/error_codes.ml +++ b/src/lang_utils/error_codes.ml @@ -144,7 +144,7 @@ let error_codes : (string * string option) list = "M0138", None; (* Actor classes are not supported *) "M0139", None; (* Inner actor classes are not supported *) "M0140", None; (* Actor classes with type parameters are not supported *) - "M0141", None; (* Forbidden declaration in program *) + "M0141", Some([%blob "lang_utils/error_codes/M0141.md"]); (* An actor or actor class must be the only non-imported declaration in a program *) "M0142", None; (* An imported library should be a module or named actor class *) "M0143", None; (* Imported actor class cannot be anonymous *) "M0144", None; (* Expected a module or actor class *) diff --git a/src/lang_utils/error_codes/M0141.md b/src/lang_utils/error_codes/M0141.md new file mode 100644 index 00000000000..8614381f489 --- /dev/null +++ b/src/lang_utils/error_codes/M0141.md @@ -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 }; + +} +``` + diff --git a/src/mo_frontend/typing.ml b/src/mo_frontend/typing.ml index 350747ccc99..18be0d87362 100644 --- a/src/mo_frontend/typing.ml +++ b/src/mo_frontend/typing.ml @@ -2974,18 +2974,29 @@ let is_actor_dec d = obj_sort.it = T.Actor | _ -> false -let check_actors ?(viper_mode=false) scope progs : unit Diag.result = +let check_actors ?(viper_mode=false) ?(check_actors=false) scope progs : unit Diag.result = + if not check_actors then Diag.return () else Diag.with_message_store (fun msgs -> recover_opt (fun progs -> let prog = (CompUnit.combine_progs progs).it in let env = env_of_scope ~viper_mode msgs scope in + let report ds = + match ds with + [] -> () + | d :: _ -> + let r = { d.at with right = (Lib.List.last ds).at.right } in + local_error env r "M0141" "move these declarations into the body of the main actor or actor class" + in let rec go ds = function | [] -> () | (d::ds') when is_actor_dec d -> - if ds <> [] || ds' <> [] then + if ds <> [] || ds' <> [] then begin + report (List.rev ds); + report ds'; error_in [Flags.ICMode; Flags.RefMode] env d.at "M0141" "an actor or actor class must be the only non-imported declaration in a program" + end | (d::ds') when is_import d -> go ds ds' | (d::ds') -> go (d::ds) ds' in diff --git a/src/mo_frontend/typing.mli b/src/mo_frontend/typing.mli index b342cd38ecf..be0d8b40b7e 100644 --- a/src/mo_frontend/typing.mli +++ b/src/mo_frontend/typing.mli @@ -9,7 +9,7 @@ val initial_scope : scope val infer_prog : ?viper_mode:bool -> scope -> string option -> Async_cap.async_cap -> Syntax.prog -> (typ * scope) Diag.result val check_lib : scope -> string option -> Syntax.lib -> scope Diag.result -val check_actors : ?viper_mode:bool -> scope -> Syntax.prog list -> unit Diag.result +val check_actors : ?viper_mode:bool -> ?check_actors:bool -> scope -> Syntax.prog list -> unit Diag.result val check_stab_sig : scope -> Syntax.stab_sig -> (field list) Diag.result val heartbeat_type : typ diff --git a/src/pipeline/pipeline.ml b/src/pipeline/pipeline.ml index d24ebee6b14..630abc386f8 100644 --- a/src/pipeline/pipeline.ml +++ b/src/pipeline/pipeline.ml @@ -421,13 +421,14 @@ let chase_imports parsefn senv0 imports : (Syntax.lib list * Scope.scope) Diag.r in Diag.map (fun () -> (List.rev !libs, !senv)) (go_set None imports) -let load_progs ?(viper_mode=false) parsefn files senv : load_result = +let load_progs ?(viper_mode=false) ?(check_actors=false) parsefn files senv : load_result = let open Diag.Syntax in let* parsed = Diag.traverse (parsefn Source.no_region) files in let* rs = resolve_progs parsed in let progs' = List.map fst rs in let libs = List.concat_map snd rs in let* libs, senv' = chase_imports parsefn senv libs in + let* () = Typing.check_actors ~viper_mode ~check_actors senv' progs' in let* senv'' = check_progs ~viper_mode senv' progs' in Diag.return (libs, progs', senv'') @@ -510,7 +511,7 @@ type viper_result = (string * (Source.region -> Source.region option)) Diag.resu let viper_files' parsefn files : viper_result = let open Diag.Syntax in let* libs, progs, senv = load_progs ~viper_mode:true parsefn files initial_stat_env in - let* () = Typing.check_actors ~viper_mode:true senv progs in + let* () = Typing.check_actors ~viper_mode:true ~check_actors:true senv progs in let prog = CompUnit.combine_progs progs in let u = CompUnit.comp_unit_of_prog false prog in let reqs = Viper.Common.init_reqs () in @@ -525,8 +526,7 @@ let viper_files files : viper_result = let generate_idl files : Idllib.Syntax.prog Diag.result = let open Diag.Syntax in - let* libs, progs, senv = load_progs parse_file files initial_stat_env in - let* () = Typing.check_actors senv progs in + let* libs, progs, senv = load_progs ~check_actors:true parse_file files initial_stat_env in Diag.return (Mo_idl.Mo_to_idl.prog (progs, senv)) (* Running *) @@ -760,8 +760,7 @@ and compile_progs mode do_link libs progs : Wasm_exts.CustomModule.extended_modu let compile_files mode do_link files : compile_result = let open Diag.Syntax in - let* libs, progs, senv = load_progs parse_file files initial_stat_env in - let* () = Typing.check_actors senv progs in + let* libs, progs, senv = load_progs ~check_actors:true parse_file files initial_stat_env in let idl = Mo_idl.Mo_to_idl.prog (progs, senv) in let ext_module = compile_progs mode do_link libs progs in (* validate any stable type signature *) diff --git a/src/pipeline/pipeline.mli b/src/pipeline/pipeline.mli index f7b3ca4e298..14567b8f2f2 100644 --- a/src/pipeline/pipeline.mli +++ b/src/pipeline/pipeline.mli @@ -38,4 +38,4 @@ val compile_files : Flags.compile_mode -> bool -> string list -> compile_result (* For use in the IDE server *) type load_result = (Syntax.lib list * Syntax.prog list * Scope.scope) Diag.result -val load_progs : ?viper_mode:bool -> parse_fn -> string list -> Scope.scope -> load_result +val load_progs : ?viper_mode:bool -> ?check_actors:bool -> parse_fn -> string list -> Scope.scope -> load_result diff --git a/test/run-drun/bad-actor.mo b/test/run-drun/bad-actor.mo new file mode 100644 index 00000000000..22dd764c847 --- /dev/null +++ b/test/run-drun/bad-actor.mo @@ -0,0 +1,12 @@ + +// bad leading decs +type T1 = {}; +type T2 = {}; + +actor Self { + +}; + +// bad trailing decs +type U1 = {}; +type U2 = {}; diff --git a/test/run-drun/ok/bad-actor.comp-ref.ok b/test/run-drun/ok/bad-actor.comp-ref.ok new file mode 100644 index 00000000000..fdf92cd5407 --- /dev/null +++ b/test/run-drun/ok/bad-actor.comp-ref.ok @@ -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.) diff --git a/test/run-drun/ok/bad-actor.comp-ref.ret.ok b/test/run-drun/ok/bad-actor.comp-ref.ret.ok new file mode 100644 index 00000000000..69becfa16f9 --- /dev/null +++ b/test/run-drun/ok/bad-actor.comp-ref.ret.ok @@ -0,0 +1 @@ +Return code 1 diff --git a/test/run-drun/ok/bad-actor.comp.ok b/test/run-drun/ok/bad-actor.comp.ok new file mode 100644 index 00000000000..0cb77bd1be3 --- /dev/null +++ b/test/run-drun/ok/bad-actor.comp.ok @@ -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.) diff --git a/test/run-drun/ok/bad-actor.comp.ret.ok b/test/run-drun/ok/bad-actor.comp.ret.ok new file mode 100644 index 00000000000..69becfa16f9 --- /dev/null +++ b/test/run-drun/ok/bad-actor.comp.ret.ok @@ -0,0 +1 @@ +Return code 1 diff --git a/test/run-drun/ok/issue-1938-b.comp-ref.ok b/test/run-drun/ok/issue-1938-b.comp-ref.ok index f27ab90c988..c8c5672b5d2 100644 --- a/test/run-drun/ok/issue-1938-b.comp-ref.ok +++ b/test/run-drun/ok/issue-1938-b.comp-ref.ok @@ -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.) diff --git a/test/run-drun/ok/issue-1938-b.comp.ok b/test/run-drun/ok/issue-1938-b.comp.ok index f27ab90c988..4ac7d82a2b2 100644 --- a/test/run-drun/ok/issue-1938-b.comp.ok +++ b/test/run-drun/ok/issue-1938-b.comp.ok @@ -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.) diff --git a/test/run-drun/ok/issue-1938-c.comp-ref.ok b/test/run-drun/ok/issue-1938-c.comp-ref.ok index fbb596e1e64..d65e9849406 100644 --- a/test/run-drun/ok/issue-1938-c.comp-ref.ok +++ b/test/run-drun/ok/issue-1938-c.comp-ref.ok @@ -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.) diff --git a/test/run-drun/ok/issue-1938-c.comp.ok b/test/run-drun/ok/issue-1938-c.comp.ok index fbb596e1e64..69d7fd57daa 100644 --- a/test/run-drun/ok/issue-1938-c.comp.ok +++ b/test/run-drun/ok/issue-1938-c.comp.ok @@ -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.) diff --git a/test/run-drun/ok/issue-1938-d.comp-ref.ok b/test/run-drun/ok/issue-1938-d.comp-ref.ok index 1f397d76248..42753c71ba4 100644 --- a/test/run-drun/ok/issue-1938-d.comp-ref.ok +++ b/test/run-drun/ok/issue-1938-d.comp-ref.ok @@ -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.) diff --git a/test/run-drun/ok/issue-1938-d.comp.ok b/test/run-drun/ok/issue-1938-d.comp.ok index f0d74195083..f635211710b 100644 --- a/test/run-drun/ok/issue-1938-d.comp.ok +++ b/test/run-drun/ok/issue-1938-d.comp.ok @@ -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.) diff --git a/test/run-drun/ok/issue-1938.comp-ref.ok b/test/run-drun/ok/issue-1938.comp-ref.ok index 05e386770e2..f6ae7437fb9 100644 --- a/test/run-drun/ok/issue-1938.comp-ref.ok +++ b/test/run-drun/ok/issue-1938.comp-ref.ok @@ -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.) diff --git a/test/run-drun/ok/issue-1938.comp.ok b/test/run-drun/ok/issue-1938.comp.ok index 05e386770e2..de3d87b2e4c 100644 --- a/test/run-drun/ok/issue-1938.comp.ok +++ b/test/run-drun/ok/issue-1938.comp.ok @@ -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.) diff --git a/test/run-drun/ok/unavailable-constructor.comp-ref.ok b/test/run-drun/ok/unavailable-constructor.comp-ref.ok index 717072c267b..3f382f39fce 100644 --- a/test/run-drun/ok/unavailable-constructor.comp-ref.ok +++ b/test/run-drun/ok/unavailable-constructor.comp-ref.ok @@ -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 diff --git a/test/run-drun/ok/unavailable-constructor.comp.ok b/test/run-drun/ok/unavailable-constructor.comp.ok index 717072c267b..3f382f39fce 100644 --- a/test/run-drun/ok/unavailable-constructor.comp.ok +++ b/test/run-drun/ok/unavailable-constructor.comp.ok @@ -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 diff --git a/test/run-drun/ok/unavailable-constructor.tc.ok b/test/run-drun/ok/unavailable-constructor.tc.ok index 76a50669881..136629772f2 100644 --- a/test/run-drun/ok/unavailable-constructor.tc.ok +++ b/test/run-drun/ok/unavailable-constructor.tc.ok @@ -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`) diff --git a/test/run-drun/ok/unsupported-more.comp-ref.ok b/test/run-drun/ok/unsupported-more.comp-ref.ok index ddecbbe0fae..968a5fa7fa8 100644 --- a/test/run-drun/ok/unsupported-more.comp-ref.ok +++ b/test/run-drun/ok/unsupported-more.comp-ref.ok @@ -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.) diff --git a/test/run-drun/ok/unsupported-more.comp.ok b/test/run-drun/ok/unsupported-more.comp.ok index ddecbbe0fae..26675e1ca94 100644 --- a/test/run-drun/ok/unsupported-more.comp.ok +++ b/test/run-drun/ok/unsupported-more.comp.ok @@ -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.) diff --git a/test/run-drun/ok/unsupported.comp-ref.ok b/test/run-drun/ok/unsupported.comp-ref.ok index 5377b5cb83c..3da550bcfde 100644 --- a/test/run-drun/ok/unsupported.comp-ref.ok +++ b/test/run-drun/ok/unsupported.comp-ref.ok @@ -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.) diff --git a/test/run-drun/ok/unsupported.comp.ok b/test/run-drun/ok/unsupported.comp.ok index 0133928e5f8..2c76a5b030d 100644 --- a/test/run-drun/ok/unsupported.comp.ok +++ b/test/run-drun/ok/unsupported.comp.ok @@ -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.) diff --git a/test/run-drun/ok/unsupported.tc.ok b/test/run-drun/ok/unsupported.tc.ok index 9ab0f7bac00..d99fa829ee6 100644 --- a/test/run-drun/ok/unsupported.tc.ok +++ b/test/run-drun/ok/unsupported.tc.ok @@ -2,10 +2,10 @@ unsupported.mo:4.26-4.44: warning [M0194], unused identifier bad_private_shared unsupported.mo:6.29-6.30: warning [M0194], unused identifier a (delete or rename to wildcard `_` or `_a`) unsupported.mo:8.32-8.33: warning [M0194], unused identifier f (delete or rename to wildcard `_` or `_f`) unsupported.mo:30.13-30.14: warning [M0194], unused identifier a (delete or rename to wildcard `_` or `_a`) -unsupported.mo:36.13-36.23: warning [M0194], unused identifier bad_shared (delete or rename to wildcard `_` or `_bad_shared`) -unsupported.mo:50.15-50.28: warning [M0194], unused identifier BadActorClass (delete or rename to wildcard `_` or `_BadActorClass`) -unsupported.mo:54.15-54.28: warning [M0194], unused identifier BadActorClass (delete or rename to wildcard `_` or `_BadActorClass`) -unsupported.mo:54.30-54.31: warning [M0194], unused identifier x (delete or rename to wildcard `_` or `_x`) -unsupported.mo:58.6-58.23: warning [M0194], unused identifier bad_non_top_actor (delete or rename to wildcard `_` or `_bad_non_top_actor`) -unsupported.mo:62.7-62.23: warning [M0194], unused identifier bad_nested_actor (delete or rename to wildcard `_` or `_bad_nested_actor`) -unsupported.mo:69.6-69.20: warning [M0194], unused identifier implicit_async (delete or rename to wildcard `_` or `_implicit_async`) +unsupported.mo:36.23-36.33: warning [M0194], unused identifier bad_shared (delete or rename to wildcard `_` or `_bad_shared`) +unsupported.mo:50.23-50.36: warning [M0194], unused identifier BadActorClass (delete or rename to wildcard `_` or `_BadActorClass`) +unsupported.mo:54.23-54.36: warning [M0194], unused identifier BadActorClass (delete or rename to wildcard `_` or `_BadActorClass`) +unsupported.mo:54.38-54.39: warning [M0194], unused identifier x (delete or rename to wildcard `_` or `_x`) +unsupported.mo:58.14-58.31: warning [M0194], unused identifier bad_non_top_actor (delete or rename to wildcard `_` or `_bad_non_top_actor`) +unsupported.mo:62.15-62.31: warning [M0194], unused identifier bad_nested_actor (delete or rename to wildcard `_` or `_bad_nested_actor`) +unsupported.mo:67.16-67.30: warning [M0194], unused identifier implicit_async (delete or rename to wildcard `_` or `_implicit_async`) diff --git a/test/run-drun/unavailable-constructor.mo b/test/run-drun/unavailable-constructor.mo index a6deed6c1f6..2edf43bc2b1 100644 --- a/test/run-drun/unavailable-constructor.mo +++ b/test/run-drun/unavailable-constructor.mo @@ -1,5 +1,3 @@ -func f() : async () { ignore await C(); }; - actor class C() { let _ : Any = C; diff --git a/test/run-drun/unsupported.mo b/test/run-drun/unsupported.mo index e2f84ba8df2..af15ed0d38d 100644 --- a/test/run-drun/unsupported.mo +++ b/test/run-drun/unsupported.mo @@ -30,45 +30,48 @@ actor Counter { let a = async { 1; }; // supported async }; -} -; - -shared func bad_shared() { }; // unsupported non actor-member - -do { - // shared function types are sharable - type wellformed_1 = shared (shared () -> ()) -> async (); -}; - -do { - // actors are shareable - type wellformed_2 = shared (actor {}) -> async (); -}; - - -do { - actor class BadActorClass () { }; // no actor classes -}; - -do { - actor class BadActorClass (x : Int) { }; // no actor classes + public func misc_unsupported () : async () { + + do { + shared func bad_shared() { }; // unsupported non actor-member + }; + + do { + // shared function types are sharable + type wellformed_1 = shared (shared () -> ()) -> async (); + }; + + do { + // actors are shareable + type wellformed_2 = shared (actor {}) -> async (); + }; + + do { + actor class BadActorClass () { }; // no actor classes + }; + + do { + actor class BadActorClass (x : Int) { }; // no actor classes + }; + + do { + let bad_non_top_actor : actor {} = if true actor {} else actor {}; + }; + + do { + let bad_nested_actor = do { let _ = actor {}; ()}; + }; + + do { + // async functions not supported (inference mode) + func implicit_async() : async () { }; + }; + + do { + // anonymous shared functions not supported (inference and checking mode) + let _ = shared func() : async () { }; + ignore (shared func() : async () { }) : shared () -> async (); + + }; + } }; - -do { - let bad_non_top_actor : actor {} = if true actor {} else actor {}; -}; - -do { - let bad_nested_actor = do { let _ = actor {}; ()}; -}; - - -actor BadSecondActor { }; - -// async functions not supported (inference mode) -func implicit_async() : async () { }; - -// anonymous shared functions not supported (inference and checking mode) -let _ = shared func() : async () { }; -(shared func() : async () { }) : shared () -> async (); -