Skip to content

Commit 7ff2619

Browse files
authored
Deprecate import of plain decs (#2020)
Fixes issue #2018
1 parent e4e1c6e commit 7ff2619

File tree

10 files changed

+36
-10
lines changed

10 files changed

+36
-10
lines changed

src/mo_def/syntax.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ let comp_unit_of_prog as_lib (prog : prog) : comp_unit =
287287
| ds' ->
288288
if as_lib
289289
then
290+
(* Deprecated syntax, see Typing.check_lib *)
290291
let fs = List.map (fun d -> {vis = Public @@ no_region; dec = d; stab = None} @@ d.at) ds' in
291292
finish imports {it = ModuleU (None, fs); at = no_region; note = empty_typ_note}
292293
else finish imports { it = ProgU ds; note = prog_typ_note; at = no_region }

src/mo_frontend/typing.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,15 @@ let check_lib scope lib : Scope.t Diag.result =
22682268
List.iter2 (fun import imp_d -> import.note <- imp_d.note.note_typ) imports imp_ds;
22692269
cub.note <- {note_typ = typ; note_eff = T.Triv};
22702270
let imp_typ = match cub.it with
2271-
| ModuleU _ -> typ
2271+
| ModuleU _ ->
2272+
if cub.at = no_region then begin
2273+
let r = Source.({
2274+
left = { no_pos with file = lib.note };
2275+
right = { no_pos with file = lib.note }})
2276+
in
2277+
warn env r "deprecated syntax: an imported library should be a module or named actor class"
2278+
end;
2279+
typ
22722280
| ActorClassU (sp, id, p, _, self_id, fields) ->
22732281
if Syntax.is_anonymous id then
22742282
error env cub.at "bad import: imported actor class cannot be anonymous";

test/fail/bad-import-decs.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import C "lib/decs"; // bad actor import
2+
3+
actor {
4+
};

test/fail/lib/decs.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let x = 666

test/fail/ok/bad-import-decs.tc.ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib/decs.mo:0.1: warning, deprecated syntax: an imported library should be a module or named actor class

test/mo-idl/import/car.mo

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
// - Server: Validate car is registered under the given name
88
// - Client: Pick a parking spot from a Google Map like interface + time
99
// - Server: Register the parking spot for the user
10-
type Car = { model : Text; plate : Text };
11-
type DMV = actor { check : Car -> async CarInfo };
12-
type CarInfo = {
13-
model : Text;
14-
plate : Text;
15-
isValid : Bool;
16-
wasStolen : Bool;
17-
expires : Nat;
18-
};
10+
module {
11+
public type Car = { model : Text; plate : Text };
12+
public type DMV = actor { check : Car -> async CarInfo };
13+
public type CarInfo = {
14+
model : Text;
15+
plate : Text;
16+
isValid : Bool;
17+
wasStolen : Bool;
18+
expires : Nat;
19+
};
20+
}

test/repl/ok/double-import.stderr.ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib/empty.mo:0.1: warning, deprecated syntax: an imported library should be a module or named actor class

test/repl/ok/nested-import.stderr.ok

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib/nested/a.mo:0.1: warning, deprecated syntax: an imported library should be a module or named actor class
2+
lib/nested.mo:0.1: warning, deprecated syntax: an imported library should be a module or named actor class
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lib/c.mo:0.1: warning, deprecated syntax: an imported library should be a module or named actor class
2+
lib/b.mo:0.1: warning, deprecated syntax: an imported library should be a module or named actor class
3+
lib/a.mo:0.1: warning, deprecated syntax: an imported library should be a module or named actor class
4+
lib/triangle.mo:0.1: warning, deprecated syntax: an imported library should be a module or named actor class

test/run/ok/import.tc.ok

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib/dir/lib.mo:0.1: warning, deprecated syntax: an imported library should be a module or named actor class
2+
lib/hello-string.mo:0.1: warning, deprecated syntax: an imported library should be a module or named actor class

0 commit comments

Comments
 (0)