You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 4827 Reporter:@mmottl Assigned to: hnrgrgr Status: closed (set by @xavierleroy on 2015-07-24T08:38:55Z) Resolution: fixed Priority: normal Severity: minor Version: 3.11.0 Target version: 4.02.0+dev Fixed in version: 3.12.1 Category: ~DO NOT USE (was: OCaml general) Monitored by:@mshinwell till lavi "Julien Signoles" jm @hcarty@yakobowski@alainfrisch@mmottl
Bug description
The following file "foo.ml" leads to a funny compile error:
module type Sig = sig
type t
val f : t -> unit
end
module type Test_sig = sig
module Make (S : sig end) : Sig with type t = int
module X : Sig
end
module Test : Test_sig = struct
module Make (S : sig end) = struct
type t = int
let f =
match 0 with
| 0 -> fun _ -> ()
| _ -> fun _ -> ()
end
module X =
struct
include Make (struct end)
end
end
The error message:
File "foo.ml", line 12, characters 25-242:
Error: Signature mismatch:
Modules do not match:
sig
module Make :
functor (S : sig end) -> sig type t = int val f : t -> unit end
module X : sig type t = int val f : t -> unit end
end
is not included in
Test_sig
Modules do not match:
sig type t = int val f : t -> unit end
is not included in
Sig
Values do not match:
val f : t -> unit
is not included in
val f : t -> unit
The last few lines, which state that "val f : t -> unit" is not included in itself, are clearly counterintuitive.
The problem is obviously related to non-generalizable type variables. The function "f" can take any type, but since it is generated through an expression, the type variable is not generalized. There are two interesting observations here:
Deleting either Make or X from Test_sig will make the file compile.
Removing "struct", "end" and "include" from the definition of X, i.e. just directly binding the result of the functor application to X, will also get rid of errors.
Besides the counterintuitive error message, especially 2) seems weird. There is no obvious reason why this code should not be accepted.
I'm not sure whether there is an easy fix for this in the compiler. In case anybody needs to work around this problem, simply constraining the type of the argument to f at the point of definition should always work, because this gets rid of the non-generalized type variable. E.g.:
let f =
match 0 with
| 0 -> fun (_ : t) -> ()
| _ -> fun _ -> ()
The text was updated successfully, but these errors were encountered:
Original bug ID: 4827
Reporter: @mmottl
Assigned to: hnrgrgr
Status: closed (set by @xavierleroy on 2015-07-24T08:38:55Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.11.0
Target version: 4.02.0+dev
Fixed in version: 3.12.1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @mshinwell till lavi "Julien Signoles" jm @hcarty @yakobowski @alainfrisch @mmottl
Bug description
The following file "foo.ml" leads to a funny compile error:
module type Sig = sig
type t
val f : t -> unit
end
module type Test_sig = sig
module Make (S : sig end) : Sig with type t = int
module X : Sig
end
module Test : Test_sig = struct
module Make (S : sig end) = struct
type t = int
end
module X =
struct
include Make (struct end)
end
end
The error message:
The last few lines, which state that "val f : t -> unit" is not included in itself, are clearly counterintuitive.
The problem is obviously related to non-generalizable type variables. The function "f" can take any type, but since it is generated through an expression, the type variable is not generalized. There are two interesting observations here:
Besides the counterintuitive error message, especially 2) seems weird. There is no obvious reason why this code should not be accepted.
I'm not sure whether there is an easy fix for this in the compiler. In case anybody needs to work around this problem, simply constraining the type of the argument to f at the point of definition should always work, because this gets rid of the non-generalized type variable. E.g.:
let f =
match 0 with
| 0 -> fun (_ : t) -> ()
| _ -> fun _ -> ()
The text was updated successfully, but these errors were encountered: