-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1491 from sliquister/ill-typed-functor
Improve error reporting for ill-typed applicative functor type
- Loading branch information
Showing
11 changed files
with
195 additions
and
53 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
83 changes: 83 additions & 0 deletions
83
testsuite/tests/typing-modules/applicative_functor_type.ml
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,83 @@ | ||
(* TEST | ||
* expect | ||
*) | ||
|
||
type t = Set.Make(String).t | ||
[%%expect{| | ||
type t = Set.Make(String).t | ||
|} ] | ||
|
||
|
||
(* Check the error messages of an ill-typed applicatived functor type. *) | ||
module M = struct type t let equal = (=) end | ||
[%%expect{| | ||
module M : sig type t val equal : 'a -> 'a -> bool end | ||
|} ] | ||
|
||
type t = Set.Make(M).t | ||
[%%expect{| | ||
Line _, characters 9-22: | ||
type t = Set.Make(M).t | ||
^^^^^^^^^^^^^ | ||
Error: The type of M does not match Set.Make's parameter | ||
Modules do not match: | ||
sig type t = M.t val equal : 'a -> 'a -> bool end | ||
is not included in | ||
Set.OrderedType | ||
The value `compare' is required but not provided | ||
File "set.mli", line 52, characters 4-31: Expected declaration | ||
|} ] | ||
|
||
|
||
(* We would report the wrong error here if we didn't strengthen the | ||
type of the argument (type t wouldn't match). *) | ||
module F(X : sig type t = M.t val equal : unit end) | ||
= struct type t end | ||
[%%expect{| | ||
module F : | ||
functor (X : sig type t = M.t val equal : unit end) -> sig type t end | ||
|} ] | ||
|
||
type t = F(M).t | ||
[%%expect{| | ||
Line _, characters 9-15: | ||
type t = F(M).t | ||
^^^^^^ | ||
Error: The type of M does not match F's parameter | ||
Modules do not match: | ||
sig type t = M.t val equal : 'a -> 'a -> bool end | ||
is not included in | ||
sig type t = M.t val equal : unit end | ||
Values do not match: | ||
val equal : 'a -> 'a -> bool | ||
is not included in | ||
val equal : unit | ||
|} ] | ||
|
||
|
||
(* MPR#7611 *) | ||
module Generative() = struct type t end | ||
[%%expect{| | ||
module Generative : functor () -> sig type t end | ||
|}] | ||
|
||
type t = Generative(M).t | ||
[%%expect{| | ||
Line _, characters 9-24: | ||
type t = Generative(M).t | ||
^^^^^^^^^^^^^^^ | ||
Error: The functor Generative is generative, it cannot be applied in type | ||
expressions | ||
|}] | ||
|
||
|
||
|
||
module F(X : sig module type S module F : S end) = struct | ||
type t = X.F(Parsing).t | ||
end | ||
[%%expect{| | ||
Line _, characters 11-25: | ||
type t = X.F(Parsing).t | ||
^^^^^^^^^^^^^^ | ||
Error: The module X.F is abstract, it cannot be applied | ||
|}] |
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,5 @@ | ||
aliases.ml | ||
applicative_functor_type.ml | ||
firstclass.ml | ||
generative.ml | ||
pr5911.ml | ||
|
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
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