Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many updates and improvements to diagnostic messages #195

Merged
merged 360 commits into from
Oct 6, 2017

Conversation

MatthewFluet
Copy link
Member

Highlights:

  • Display full region (left position through right position) in error and warning messages (8c8be24). For example:
        Error: z.sml 1.5-1.17.
          Pattern and expression disagree.
            pattern:    [int]
            expression: [bool]
            in: val x: int = true
    
    Also update scanner, parser, and precedence parser to obtain the proper regions (6faf9cd, 1b9243d, 31f108b, e6aa4e3, 8035918, 48898dd, 266e5e9, ab00ea7) and explicitly represent parenthesized types, patterns, and expressions in AST (ac63755).
  • Update Emacs page with example compilation-error-regexp-alist to support full regions and spec at: <region>, defn at: <region>, escape from: <region>, escape to: <region>, scoped to: <region> informative messages (f4ceafb, f94f6ec, 2be2a29, 76bf730, 2be2a29, 44125b0).
  • Fix minor bug with exception replication (1c89c42).
  • Fix minor bug that erroneously accepted symbolic identifiers for strid, sigid, and fctid (9a56be6).
  • Update and fix minor bug in precedence parsing of function clauses (1a6d25e).
  • Update diagnostics regarding defn/spec of special identifies (c159407, 7472bd8, 94ed3b0, e0708be, 236592b), add special identifier (failing) regression tests (eab051f), add allow{Redefine,Specify}SpecialIds expert MLB annotations (a69b4b3), allow it to be defined/specified (87f6e6e), and treat = as a special identifier (d754ac9).
  • Improve inference for fun and val rec declarations (4e3ca55, 007bd77, 0a9ab61, 4ea1f7c, 92ee067). The primary motivation is avoid the (confusing) recursive use of function disagrees with its type error message; in particular, it can be frustrating to add type constraints to a declaration in the hopes of identifying the problematic recursive use, only to have the explicit type information seemingly ignored. For example, consider the program:
        fun f (x: int) = f true
    MLton previously gave the error message:
        Error: z.sml 1.5.
          Recursive use of function disagrees with its type.
            function type:  [int] -> _
            recursive uses: [bool] -> _
            in: fun f (x: int) = (f true)
    
    MLton now gives the error message:
        Error: z.sml 1.18-1.23.
          Function applied to incorrect argument.
            expects: [int]
            but got: [bool]
            in: f true
    
  • Improve heuristics for selecting "pretty" name for type constructors in error messages (d25f6ab, 27cb830, a83b0c8, ecfb3c7, 8de0f21, 177421c, 5de0802, 2cc7a31, 89dea4d, ae3bfda).
  • Improve diagnostics for elaboration of a signature constraint applied to a structure (81c00f6, adf53ba, 0285827, a718588, 4a2ef9d, 9aed431, 5370b14, 8e2673f, 45e62ca, bdba70f, 7600597). While the region associated with a <thing> in structure disagrees with signature diagnostic corresponds to the signature constraint, in order to fix the error, at least one of the structure or signature must be modified. New defn at: <region> and spec at: <region> informative messages are added to <thing> in structure disagrees with signature diagnostics to identify the definition and specification points of the identifier. With suitable editor support (e.g., emacs compilation-error-regexp-alist), it is easy to visit one of the points to resolve the error. For example, consider the program:
        signature SIG =
           sig
              val f: int -> string
              exception E of bool
              eqtype 'a t
              datatype 'a u = U1 of 'a | U2 of 'a list | U3 of 'a * 'a
              datatype v = V1 | V2 of bool
           end
        structure Str : SIG =
           struct
              val f = Bool.toString
              val E = Fail
              type ('a, 'b) t = 'a -> 'b
              datatype 'a u = U2 of 'a | U3 of 'a * 'a | U4 of 'a option
              structure V = struct datatype v = V1 | V2 of bool end
              datatype v = V1 | V2 of bool
              datatype w = datatype V.v
           end
    MLton previously gave the error messages:
        Error: z.sml 9.17.
          Type t admits equality in signature but not in structure.
            not equality: t
        Error: z.sml 9.17.
          Constructor type in structure disagrees with signature.
            constructor: U2
            structure: ['a] -> _
            signature: ['a list] -> _
        Error: z.sml 9.17.
          Type u has constructors in structure only: U4.
        Error: z.sml 9.17.
          Type u has constructors in signature only: U1.
        Error: z.sml 9.17.
          Variable type in structure disagrees with signature.
            variable: E
            structure: [string] -> _
            signature: [bool] -> _
        Error: z.sml 9.17.
          Variable in structure but exception in signature: E.
        Error: z.sml 9.17.
          Variable U1 in signature but not in structure.
        Error: z.sml 9.17.
          Variable type in structure disagrees with signature.
            variable: U2
            structure: _ -> ['a list] u
            signature: _ -> ['a] u
        Error: z.sml 9.17.
          Variable type in structure disagrees with signature.
            variable: V1
            structure: [w]
            signature: [v]
        Error: z.sml 9.17.
          Variable type in structure disagrees with signature.
            variable: V2
            structure: _ -> [w]
            signature: _ -> [v]
        Error: z.sml 9.17.
          Variable type in structure disagrees with signature.
            variable: f
            structure: [bool] -> _
            signature: [int] -> _
    
    MLton now gives the error messages:
        Error: z.sml 9.17-9.19.
          Type in structure disagrees with signature (arity, admits equality): t.
            structure: type [('a, 'b)] t = [_ -> _]
            defn at: z.sml 13.21-13.21
            signature: [eqtype] ['a] t
            spec at: z.sml 5.17-5.17
        Error: z.sml 9.17-9.19.
          Type in structure disagrees with signature (constructors): u.
            structure: datatype 'a u = U2 of ['a] | [U4 of _] | ...
            defn at: z.sml 14.19-14.19
            signature: datatype 'a u = [U1 of _] | U2 of ['a list] | ...
            spec at: z.sml 6.19-6.19
        Error: z.sml 9.17-9.19.
          Value identifier in structure disagrees with signature (status, type): E.
            structure: [val] E: [string] -> _
            defn at: z.sml 12.11-12.11
            signature: [exn] E: [bool] -> _
            spec at: z.sml 4.17-4.17
        Error: z.sml 9.17-9.19.
          Constructor in structure disagrees with signature (type): U2.
            structure: con U2: _ -> ['a list] _str.u
            defn at: z.sml 14.23-14.24
            signature: con U2: _ -> ['a] _str.u
            spec at: z.sml 6.34-6.35
        Error: z.sml 9.17-9.19.
          Constructor in structure disagrees with signature (type): V1.
            structure: con V1: [_str.w]
            defn at: z.sml 15.41-15.42
            signature: con V1: [_str.v]
            spec at: z.sml 7.20-7.21
        Error: z.sml 9.17-9.19.
          Constructor in structure disagrees with signature (type): V2.
            structure: con V2: _ -> [_str.w]
            defn at: z.sml 15.46-15.47
            signature: con V2: _ -> [_str.v]
            spec at: z.sml 7.25-7.26
        Error: z.sml 9.17-9.19.
          Variable in structure disagrees with signature (type): f.
            structure: val f: [bool] -> _
            defn at: z.sml 11.11-11.11
            signature: val f: [int] -> _
            spec at: z.sml 3.11-3.11
    
  • Improve diagnostics for elaboration sharing type specifications and where type signature expressions (80170ac, dccddcf, e570564, 3224c6e, 054ef37, 12e494e, a9a3508, 6803627, 084003d). The new spec at: <region> informative messages show the origin and constraints of type constructors equated by sharing type and where type. For example, consider the following program:
        signature S =
           sig
              type s1
              type s2 = int
              sharing type s1 = s2
           end
    
        signature S =
           sig
              type s1
              type s2 = s1 * s1
              sharing type s1 = s2
           end
    
        signature S =
           sig
              structure T: sig type t end
              structure U:
                 sig
                    type u1 = T.t
                    type u2
                    sharing type u1 = u2
                 end
           end
    
        signature S =
           sig
              structure T: sig datatype t = T1 end
              structure U: sig type 'a u end
              structure V: sig eqtype ('a, 'b) v end
              sharing type T.t = U.u = V.v
           end
    
        signature S =
           sig
              type s = int
           end where type s = bool
    
        signature S =
           sig
              type s1
              type s2 = s1 * s1
           end where type s2 = bool
    
        signature S =
           sig
              type t
           end where type 'a t = 'a -> 'a
    
        signature S =
           sig
              eqtype t
           end where type t = unit -> unit
    
        signature S =
           sig
              eqtype 'a t
           end where type ('a, 'b) t = 'a -> 'b
    
        signature S =
           sig
              datatype t = T
           end where type 'a t = 'a -> 'a
    MLton previously gave the error messages:
        Error: z.sml 5.25.
          Type s2 is already defined as int and cannot be shared.
        Error: z.sml 12.25.
          Type s2 is a definition and cannot be shared.
        Error: z.sml 22.26.
          Type u1 is not local and cannot be shared.
        Error: z.sml 31.20.
          Type T.t has arity 0 and type U.u has arity 1 and cannot be shared.
        Error: z.sml 31.26.
          Type U.u has arity 1 and type V.v has arity 2 and cannot be shared.
        Error: z.sml 37.19.
          Type s is already defined as int and cannot be redefined.
        Error: z.sml 43.19.
          Type s2 is a definition and cannot be redefined.
        Error: z.sml 48.22.
          Type t has arity 0 and cannot be defined to have arity 1.
        Error: z.sml 53.19.
          Eqtype t cannot be defined as a non-equality type.
        Error: z.sml 58.28.
          Type t has arity 1 and cannot be defined to have arity 2.
        Error: z.sml 63.22.
          Type t has arity 0 and cannot be defined to have arity 1.
    
    MLton now gives the error messages:
        Error: z.sml 5.25-5.26.
          Type cannot be shared (defined): s2.
            type spec: type s2 = int
            spec at: z.sml 4.12-4.13
        Error: z.sml 12.25-12.26.
          Type cannot be shared (defined): s2.
            type spec: type s2 = s1 * s1
            spec at: z.sml 11.12-11.13
        Error: z.sml 22.26-22.27.
          Type cannot be shared (not local): u1.
            type spec: type u1 = T.t
            spec at: z.sml 20.18-20.19
            spec at: z.sml 17.29-17.29
            spec at: z.sml 20.23-20.25
        Error: z.sml 31.7-31.34.
          Types cannot be shared (arity): T.t, U.u.
            type spec: datatype [] T.t = ...
            spec at: z.sml 28.33-28.33
            type spec: type ['a] U.u
            spec at: z.sml 29.32-29.32
        Error: z.sml 31.7-31.34.
          Types cannot be shared (arity): U.u, V.v.
            type spec: type ['a] U.u
            spec at: z.sml 29.32-29.32
            type spec: eqtype [('a, 'b)] V.v
            spec at: z.sml 30.40-30.40
        Error: z.sml 37.19-37.19.
          Type cannot be realized (defined): s.
            type spec: type s = int
            spec at: z.sml 36.12-36.12
        Error: z.sml 43.19-43.20.
          Type cannot be realized (defined): s2.
            type spec: type s2 = _sig.s1 * _sig.s1
            spec at: z.sml 42.12-42.13
        Error: z.sml 48.8-48.33.
          Type cannot be realized (arity): t.
            type spec: type [] t
            spec at: z.sml 47.12-47.12
            type defn: type ['a] t = ...
        Error: z.sml 53.8-53.34.
          Type cannot be realized (admits equality): t.
            type spec: [eqtype] t
            spec at: z.sml 52.14-52.14
            type defn: type t = [_ -> _]
        Error: z.sml 58.8-58.39.
          Type cannot be realized (arity, admits equality): t.
            type spec: [eqtype] ['a] t
            spec at: z.sml 57.17-57.17
            type defn: type [('a, 'b)] t = [_ -> _]
        Error: z.sml 63.8-63.33.
          Type cannot be realized (arity, type structure): t.
            type spec: [datatype] [] t = ...
            spec at: z.sml 62.16-62.16
            type defn: type ['a] t = ['a -> 'a]
    
  • Improve diagnostics for "time-based" (i.e., use of type constructor or type variable escapes scope) diagnostics (c5db99b, 39541ee, 4bc78b9, 23a24b9, e76223c, 2be2a29). New escaping from: <region> and escaping to: <region> informative messages show the definition point of escaping type constructors and the declaration region of unification variables being unified. For example, consider the program:
        structure S:
        sig
           type t
           val f: ('a * t) option -> ('a * t) option
        end =
        struct
           val rf = ref NONE
           val f = fn z => (!rf before rf := z)
           datatype t = T
        end
    
        val _ =
           let
              datatype u = U
              datatype 'a t = T of 'a
           in
              (T U, fn (T U) => ())
           end
    MLton previously gave the error messages:
        Error: z.sml 7.4.
          Type escapes the scope of its definition at z.sml 9.13.
            type: S.t
            in: val rf = ref NONE
        Error: z.sml 2.1.
          Variable type in structure disagrees with signature.
            variable: f
            unable to generalize: 'a
            signature: ('a * t) option -> ('a * t) option
        Error: z.sml 12.1.
          Type escapes the scope of its definition at z.sml 15.19.
            type: t
            in: val _ = let datatype u = U dataty  ...  U, fn T U => ()) end
        Error: z.sml 12.1.
          Type escapes the scope of its definition at z.sml 14.16.
            type: u
            in: val _ = let datatype u = U dataty  ...  U, fn T U => ()) end
    
    MLton now gives the error messages:
        Error: z.sml 2.1-5.3.
          Variable in structure disagrees with signature (type): f.
            structure: val f: ([???] * [???]) option -> ([???] * [???]) option
            defn at: z.sml 8.8-8.8
            signature: val f: (['a] * [_str.t]) option -> (['a] * [_str.t]) option
            spec at: z.sml 4.8-4.8
            note: types would escape their scope: _str.t, 'a
            escape from: z.sml 9.13-9.13
            escape to: z.sml 7.4-7.20
        Error: z.sml 13.4-18.6.
          Type of let has local types that would escape their scope: t, u.
            type: [u t] * ([u t] -> _)
            escape from: z.sml 15.19-15.19
            escape from: z.sml 14.16-14.16
            in: let datatype u = U datatype 'a t   ...  U, fn T U => ()) end
        Warning: z.sml 7.8-7.9.
          Type of variable was not inferred and could not be generalized: rf.
            type: (??? * ???) option ref
            in: val rf = ref NONE
        Warning: z.sml 8.8-8.8.
          Type of variable was not inferred and could not be generalized: f.
            type: (??? * ???) option -> (??? * ???) option
            in: val f = fn z => (! rf before rf := z)
    
  • Improve -show-basis <file> display of information (a14c363, a95aabd).
  • Improve treatment of explicit and implicit type variables (76e59c4, 41b1fb3, b5b3271, b73f133, 44125b0).
  • Fix bug in elaboration of structure S1 = S2 = S3 = ... = Sn (f2e88a4, 9cb5164, 198f585).
  • Improve treatment of unification errors between an equality unification variable and a non-equality type (5667be6).
  • Make non-trivial changes to elaboration infrastructure: allow elaboration to proceed after errors (a509a94, 68bcb27, db3e85c); gensym bogus types rather than use exn or unit (48f0f79); make "time" of tyvars and tycons immutable and eliminate useBeforeDef component of TypeEnv.Time.t (a4d81f2, c5db99b, 39541ee, 11c32be, 422e379, a9ace8d, b72ee8d, 87cde1f); properly separate AST Tyvar from Elaborate/CoreML Tyvar (76e59c4); simplify type variable scope inference (fb516c6, 34cfb55); eliminate preError from elaboration (a3d96c9); simplify ElaborateEnv.Equality type and operations (2cdfe15); close a space leak with TypeEnv.Type.newCloses (6893e89); alternative implementation of TypeEnv.close (d8fb739); refactor ElaborateEnv (d1a850c, 24b5308, 3d5fffe, 465de43, 6bdcc14, 844d421). The general theme has been to eliminate or reduce the use of mutation.

Overall, no significant impact on performance (when self-compiling)::

    MLton 20170927.130420-gd4e3a42
    MLton starting
       Type Check SML starting
       Type Check SML finished in 12.55 + 4.97 (28% GC)
    MLton finished in 12.55 + 4.97 (28% GC)
    GC type         time ms  number           bytes       bytes/sec
    -------------   ------- ------- --------------- ---------------
    copying           4,444      13   2,673,818,072     601,669,242
    mark-compact          0       0               0               -
    minor                 0       0               0               -
    total time: 17,536 ms
    total GC time: 4,972 ms (28.4%)
    max pause time: 1,960 ms
    total bytes allocated: 15,298,792,872 bytes
    max bytes live: 1,009,610,624 bytes
    max heap size: 8,076,926,976 bytes
    max stack size: 11,730,944 bytes
    num cards marked: 0
    bytes scanned: 0 bytes
    bytes hash consed: 0 bytes


    MLton 20171004.203723-g09b5734
    MLton starting
       Type Check SML starting
       Type Check SML finished in 12.64 + 4.60 (27% GC)
    MLton finished in 12.64 + 4.60 (27% GC)
    GC type         time ms  number           bytes       bytes/sec
    -------------   ------- ------- --------------- ---------------
    copying           4,028      14   2,655,669,568     659,302,260
    mark-compact          0       0               0               -
    minor                 0       0               0               -
    total time: 17,256 ms
    total GC time: 4,600 ms (26.7%)
    max pause time: 1,684 ms
    total bytes allocated: 15,982,153,400 bytes
    max bytes live: 934,434,648 bytes
    max heap size: 7,475,544,064 bytes
    max stack size: 11,354,112 bytes
    num cards marked: 0
    bytes scanned: 0 bytes
    bytes hash consed: 0 bytes

Consider the following program:

    structure S :
    sig
       type ('a, 'b) t
       eqtype ('a, 'b) u
       type 'a v = ('a, 'a) t * 'a * ('a, 'a) t
       type 'a w = ('a, 'a) u * 'a * ('a, 'a) u
       datatype 'a x = X of ('a, 'a) t
       datatype 'a y = Y of ('a, 'a) u
    end = struct end

Previously, MLton generated the following error messages:

    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: t.
        signature: type ('a, 'b) t = ('a, 'b) _sig.t
        spec at:   z.sml 3.18-3.18
    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: u.
        signature: eqtype ('a, 'b) u = ('a, 'b) _sig.u
        spec at:   z.sml 4.20-4.20
    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: v.
        signature: type 'a v = ('a, 'a) _sig.t * 'a * ('a, 'a) _sig.t
        spec at:   z.sml 5.12-5.12
    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: w.
        signature: eqtype 'a w = ('a, 'a) _sig.u * 'a * ('a, 'a) _sig.u
        spec at:   z.sml 6.12-6.12
    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: x.
        signature: datatype 'a x = X of ('a, 'a) _sig.t
        spec at:   z.sml 7.16-7.16
    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: y.
        signature: datatype 'a y = Y of ('a, 'a) _sig.u
        spec at:   z.sml 8.16-8.16

Note that the first two error messages are rather vacuous, asserting
that a type specified in the signature is equal to itself, while the
fourth error message asserts "eqtype", although the specification in
the signature is a realized "type".

Now, MLton generates the following error messages:

    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: t.
        signature: type ('b, 'a) t
        spec at:   z.sml 3.18-3.18
    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: u.
        signature: eqtype ('b, 'a) u
        spec at:   z.sml 4.20-4.20
    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: v.
        signature: type 'a v = ('a, 'a) _sig.t * 'a * ('a, 'a) _sig.t
        spec at:   z.sml 5.12-5.12
    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: w.
        signature: type 'a w = ('a, 'a) _sig.u * 'a * ('a, 'a) _sig.u
        spec at:   z.sml 6.12-6.12
    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: x.
        signature: datatype 'a x = X of ('a, 'a) _sig.t
        spec at:   z.sml 7.16-7.16
    Error: z.sml 2.1-9.3.
      Type in signature but not in structure: y.
        signature: datatype 'a y = Y of ('a, 'a) _sig.u
        spec at:   z.sml 8.16-8.16
When there are elaboration errors, the compilation is effectively
'elaborateOnly'.
Due to the expansion of `e1 andalso e2` into
`if e1 then false else e2`, the elaborated type of an `andalso`
expression is taken to be the elaborated type of `e2`, even if `e2` is
known not to be of type bool.  Similarly, the elaborated type of
`e: ty` is the elaborated type of `e`, even if `e` is known not to be
of type `ty`.

In these cases, force the type of the elaborated expression to be
`bool` or `ty`, respectively, which can reduce spurious subsequent
errors.
In a `val rec` declaration that binds multiple variables (in a correct
program, such variables must be (nested) layered patterns), all AST
variables must be mapped to the same CoreML variable, as only one
variable is bound in the CoreML program.

The `regression/valrec.sml` program triggered the bug.
Use `Avar.region` of the variable, rather then the region of the
declaration.
In `<spec> sharing <longtycon1> = <longtycon2>`, the `<longtycon1>`
and `<longtycon2>` should be found in the environment of `<spec>`;
i.e., they should not be found in the outer environment in which the
`<spec> sharping <longtycon1> = <longtycon2>` is elaborated.

Consider the following program:

    signature A =
    sig
       type a
       sharing type a = unit
    end

    signature B =
    sig
       type b
       structure C:
          sig
             type c
             sharing type c = b
          end
    end

    signature T = sig type t end

    structure D: T =
    struct
      type t = unit
    end

    signature E =
    sig
      structure F: T
      sharing F = D
    end

    signature G =
    sig
      structure H: T
      structure I:
         sig
            structure J: T
            sharing H = J
         end
    end

Previously, MLton generated the following error messages:

    Error: z.sml 4.21-4.24.
      Type unit is a definition and cannot be shared.
    Error: z.sml 13.27-13.27.
      Type b is not local and cannot be shared.
    Error: z.sml 27.15-27.15.
      Undefined structure: D.
    Error: z.sml 36.17-36.17.
      Type H.t is not local and cannot be shared.

This correctly rejects the program, but (arguably) for the wrong
reasons.

Now, MLton generates the following error messages:

    Error: z.sml 4.21-4.24.
      Undefined type unit.
    Error: z.sml 13.27-13.27.
      Undefined type b.
    Error: z.sml 27.15-27.15.
      Undefined structure D.
    Error: z.sml 36.17-36.17.
      Undefined structure H.

which better corresponds to a scoping error.
Consider the following program:

    structure Z:
    sig
       type ('a, 'b, 'c) t
    end =
    struct
       type 'a t = unit
    end

Previously, MLton generated the following error message:

    Error: z.sml 2.1-4.3.
      Type in structure disagrees with signature (arity): t.
        structure: type ['a] t = ...
        defn at:   z.sml 6.12-6.12
        signature: type [('a, 'c, 'b)] t
        spec at:   z.sml 3.22-3.22

Note that type variables in the signature specification are not in
alphabetical order, owing to the fact that `Vector.toListMap`
traverses the vector from right to left when forcing the pretty names
of the type variables.

Now, MLton generates the following error message:

    Error: z.sml 2.1-4.3.
      Type in structure disagrees with signature (arity): t.
        structure: type ['a] t = ...
        defn at:   z.sml 6.12-6.12
        signature: type [('a, 'b, 'c)] t
        spec at:   z.sml 3.22-3.22
Consider the following program:

    signature S =
    sig
       type s1
       type s2 = int
       sharing type s1 = s2
    end

    signature S =
    sig
       type s1
       type s2 = s1 * s1
       sharing type s1 = s2
    end

    signature S =
    sig
       structure T: sig type t end
       structure U:
          sig
             type u1 = T.t
             type u2
             sharing type u1 = u2
          end
    end

    signature S =
    sig
       structure T: sig datatype t = T1 end
       structure U: sig type 'a u end
       structure V: sig eqtype ('a, 'b) v end
       sharing type T.t = U.u = V.v
    end

    signature S =
    sig
       type s = int
    end where type s = bool

    signature S =
    sig
       type s1
       type s2 = s1 * s1
    end where type s2 = bool

    signature S =
    sig
       type t
    end where type 'a t = 'a -> 'a

    signature S =
    sig
       eqtype t
    end where type t = unit -> unit

    signature S =
    sig
       eqtype 'a t
    end where type ('a, 'b) t = 'a -> 'b

    signature S =
    sig
       datatype t = T
    end where type 'a t = 'a -> 'a

Previously, MLton generated the following error messages:

    Error: z.sml 5.22-5.23.
      Type s2 is already defined as int and cannot be shared.
    Error: z.sml 12.22-12.23.
      Type s2 is a definition and cannot be shared.
    Error: z.sml 22.23-22.24.
      Type u1 is not local and cannot be shared.
    Error: z.sml 31.4-31.31.
      Type T.t has arity 0 and type U.u has arity 1 and cannot be shared.
    Error: z.sml 31.4-31.31.
      Type U.u has arity 1 and type V.v has arity 2 and cannot be shared.
    Error: z.sml 37.5-37.23.
      Type s is already defined as int and cannot be redefined.
    Error: z.sml 43.5-43.24.
      Type s2 is a definition and cannot be redefined.
    Error: z.sml 48.5-48.30.
      Type t has arity 0 and cannot be defined to have arity 1.
    Error: z.sml 53.5-53.31.
      Eqtype t cannot be defined as a non-equality type.
    Error: z.sml 58.5-58.36.
      Type t has arity 1 and cannot be defined to have arity 2.
    Error: z.sml 63.5-63.30.
      Type t has arity 0 and cannot be defined to have arity 1.

Now, MLton generates the following error messages:

    Error: z.sml 5.22-5.23.
      Type cannot be shared (defined): s2.
        type spec: type s2 = [...]
        spec at:   z.sml 4.9-4.10
    Error: z.sml 12.22-12.23.
      Type cannot be shared (defined): s2.
        type spec: type s2 = [...]
        spec at:   z.sml 11.9-11.10
    Error: z.sml 22.23-22.24.
      Type cannot be shared (not local): u1.
        type spec: type u1
        spec at:   z.sml 20.15-20.16
    Error: z.sml 31.4-31.31.
      Types cannot be shared (arity): T.t, U.u.
        type spec: datatype [] T.t = ...
        spec at:   z.sml 28.30-28.30
        type spec: type ['a] U.u
        spec at:   z.sml 29.29-29.29
    Error: z.sml 31.4-31.31.
      Types cannot be shared (arity): U.u, V.v.
        type spec: type ['a] U.u
        spec at:   z.sml 29.29-29.29
        type spec: eqtype [('b, 'a)] V.v
        spec at:   z.sml 30.37-30.37
    Error: z.sml 37.16-37.16.
      Type cannot be realized (defined): s.
        type spec: type s = [...]
        spec at:   z.sml 36.9-36.9
    Error: z.sml 43.16-43.17.
      Type cannot be realized (defined): s2.
        type spec: type s2 = [...]
        spec at:   z.sml 42.9-42.10
    Error: z.sml 48.5-48.30.
      Type cannot be realized (arity): t.
        type spec: type [] t
        spec at:   z.sml 47.9-47.9
        type defn: <arity 1>
    Error: z.sml 53.5-53.31.
      Type cannot be realized (admits equality): t.
        type spec: [eqtype] t
        spec at:   z.sml 52.11-52.11
        type defn: <non-equality>
    Error: z.sml 58.5-58.36.
      Type cannot be realized (arity, admits equality): t.
        type spec: [eqtype] ['a] t
        spec at:   z.sml 57.14-57.14
        type defn: <arity 2>, <non-equality>
    Error: z.sml 63.5-63.30.
      Type cannot be realized (arity, admits equality, type structure): t.
        type spec: [datatype] [] t = ...
        spec at:   z.sml 62.13-62.13
        type defn: <arity 1>, <non-equality>, <complex type>
Previously, when creating a type structure from a scheme that was an
eta-expansion of a type constructor, the type structure was recorded
as a Tycon, rather than as a Scheme.  But, this makes it difficult to
determine if the specification was abstract (`type t`) or a
definition (`type t = int`).

Shift the eta-check to Interface.TypeStr.toTyconOpt.
Rather than using `exn` for unknown types, gensym a bogus type.

Also, when a type constructor is applied to the wrong number of type
arguments, either take from or add to the given types to obtain the
right number of type arguments.  In particular, this preserves the
type constructor.
When a type constructor is applied to the wrong number of type
arguments, either take from or add to the given types to obtain the
right number of type arguments.  In particular, this preserves the
type constructor.
Like 5d0158f.

Previously, when creating a type structure from a scheme that was an
eta-expansion of a type constructor, the type structure was recorded
as a Tycon, rather than as a Scheme.

Shift the eta-check to Interface.TypeStr.toTyconOpt.
Share the infrastructure for extending an environment.
Consider the following program:

    datatype a = A
    signature T =
       sig
          type a = a
          type b
          type c
          type d
          type t = a * b * c * d -> unit
       end
    signature S =
       sig
          type a
          type c
          structure T1:
             sig
                structure T2 :
                   sig
                      include T where type b = a
                                where type d = c
                   end
             end where type T2.t = unit
          structure T3:
             sig
                structure T4 :
                   sig
                      include T where type b = a
                                where type d = c
                   end
             end
          structure T5:
             sig
                structure T6 :
                   sig
                      include T where type b = a
                                where type d = c
                   end
             end
          sharing type T3.T4.t = T5.T6.t
       end

Previously, MLton generated the following error messages:

    Error: z.sml 21.25-21.28.
      Type cannot be realized (defined): T2.t.
        type spec: type T2.t = a * _sig.a * _sig.T1.T2.c * _sig.c -> unit
        spec at: z.sml 8.12-8.12
    Error: z.sml 38.20-38.26.
      Type cannot be shared (defined): T3.T4.t.
        type spec: type T3.T4.t = a * _sig.a * _sig.T3.T4.c * _sig.c -> unit
        spec at: z.sml 8.12-8.12
    Error: z.sml 38.30-38.36.
      Type cannot be shared (defined): T5.T6.t.
        type spec: type T5.T6.t = a * _sig.a * _sig.T5.T6.c * _sig.c -> unit
        spec at: z.sml 8.12-8.12

Although the use of "_sig" could be explained as "the top-level
signature being elaborated", it can still be confusing when shadowed
type constructors are not displayed with "?." prefixes.

Now, MLton generates the following error messages:

    Error: z.sml 21.25-21.28.
      Type cannot be realized (defined): T2.t.
        type spec: type T2.t = ?.a * a * _sig.T2.c * c -> unit
        spec at: z.sml 8.12-8.12
    Error: z.sml 38.20-38.26.
      Type cannot be shared (defined): T3.T4.t.
        type spec: type T3.T4.t = ?.a * a * T3.T4.c * c -> unit
        spec at: z.sml 8.12-8.12
    Error: z.sml 38.30-38.36.
      Type cannot be shared (defined): T5.T6.t.
        type spec: type T5.T6.t = ?.a * a * T5.T6.c * c -> unit
        spec at: z.sml 8.12-8.12

Now, the displayed type definition is relative to the environment at
the error point.  For "where type" signatures, a "_sig." prefix is
used for flexible type constructors that only exist in the signature
being realized; the contents of that signature are not in scope at the
error point, hence the "_sig." prefix.
Consider the following program:

    datatype ('a, 'b) w = W of 'a -> 'b
    datatype x = X
    datatype y = Y of unit -> unit
    signature S =
       sig
          structure T1: sig type t end
          structure T2: sig datatype t = T end
          sharing type T1.t = T2.t
          structure T3: sig type t end
          structure T4: sig eqtype t end
          sharing type T3.t = T4.t
          eqtype 'a u
          datatype 'a v = V of 'a
          structure X1: sig datatype x = X end where type x = x
          structure X2: sig datatype x = datatype x end
       end where type 'a T1.t = unit -> unit
           where type 'a T2.t = unit -> unit
           where type T3.t = y
           where type T4.t = y
           where type u = unit -> unit
           where type ('a, 'b) v = ('a, 'b) w
           where type X1.x = unit
           where type X2.x = unit

Previously, MLton generated the following error messages

    Error: z.sml 16.8-16.40.
      Type cannot be realized (arity, admits equality, type structure): T1.t.
        type spec: [eqtype] [] T1.t
        spec at: z.sml 6.30-6.30
        spec at: z.sml 8.7-8.30
        type defn: <arity 1>, <non-equality>, <complex type>
    Error: z.sml 17.8-17.40.
      Type cannot be realized (arity, admits equality, type structure): T2.t.
        type spec: [datatype] [] T2.t = ...
        spec at: z.sml 7.34-7.34
        spec at: z.sml 8.7-8.30
        type defn: <arity 1>, <non-equality>, <complex type>
    Error: z.sml 18.8-18.26.
      Type cannot be realized (admits equality): T3.t.
        type spec: [eqtype] T3.t
        spec at: z.sml 9.30-9.30
        spec at: z.sml 11.7-11.30
        type defn: <non-equality>
    Error: z.sml 19.8-19.26.
      Type cannot be realized (admits equality): T4.t.
        type spec: [eqtype] T4.t
        spec at: z.sml 10.32-10.32
        spec at: z.sml 11.7-11.30
        type defn: <non-equality>
    Error: z.sml 20.8-20.34.
      Type cannot be realized (arity, admits equality): u.
        type spec: [eqtype] ['a] u
        spec at: z.sml 12.17-12.17
        type defn: <arity 0>, <non-equality>
    Error: z.sml 21.8-21.41.
      Type cannot be realized (arity, admits equality): v.
        type spec: [datatype] ['a] v = ...
        spec at: z.sml 13.19-13.19
        type defn: <arity 2>, <non-equality>
    Error: z.sml 22.19-22.22.
      Type cannot be realized (defined): X1.x.
        type spec: type X1.x = x
        spec at: z.sml 14.34-14.34
        spec at: z.sml 14.44-14.59
    Error: z.sml 23.19-23.22.
      Type cannot be realized (defined): X2.x.
        type spec: type X2.x = x
        spec at: z.sml 15.34-15.34

Now, MLton generates the following error messages:

    Error: z.sml 16.8-16.40.
      Type cannot be realized (arity, type structure): T1.t.
        type spec: type [] T1.t = [_sig.T2.t]
        spec at: z.sml 6.30-6.30
        spec at: z.sml 8.7-8.30
        type defn: type ['a] T1.t = [unit -> unit]
    Error: z.sml 17.8-17.40.
      Type cannot be realized (arity, type structure): T2.t.
        type spec: [datatype] [] T2.t = ...
        spec at: z.sml 7.34-7.34
        spec at: z.sml 8.7-8.30
        type defn: type ['a] T2.t = [unit -> unit]
    Error: z.sml 18.8-18.26.
      Type cannot be realized (admits equality): T3.t.
        type spec: type T3.t = [_sig.T4.t]
        spec at: z.sml 9.30-9.30
        spec at: z.sml 11.7-11.30
        type defn: type T3.t = [y]
    Error: z.sml 19.8-19.26.
      Type cannot be realized (admits equality): T4.t.
        type spec: [eqtype] T4.t
        spec at: z.sml 10.32-10.32
        spec at: z.sml 11.7-11.30
        type defn: type T4.t = [y]
    Error: z.sml 20.8-20.34.
      Type cannot be realized (arity, admits equality): u.
        type spec: [eqtype] ['a] u
        spec at: z.sml 12.17-12.17
        type defn: type [] u = [unit -> unit]
    Error: z.sml 21.8-21.41.
      Type cannot be realized (arity, admits equality): v.
        type spec: datatype ['a] v = ...
        spec at: z.sml 13.19-13.19
        type defn: type [('a, 'b)] v = [('a, 'b) w]
    Error: z.sml 22.19-22.22.
      Type cannot be realized (defined): X1.x.
        type spec: datatype X1.x = ... (* = datatype x *)
        spec at: z.sml 14.34-14.34
        spec at: z.sml 14.44-14.59
    Error: z.sml 23.19-23.22.
      Type cannot be realized (defined): X2.x.
        type spec: datatype X2.x = ... (* = datatype x *)
        spec at: z.sml 15.34-15.34
The schemes registered for def-use information are not always true
schemes.  For example, consider the following program:

    fun f (x: 'a) (y: 'b) =
       let
          fun g (z: 'c) = (z, y, x)
       in
          g ()
       end

The "scheme" registered for `f` and `g` are actually mono-types: the
unification types created for `f` and `g` at the point where they are
initially added to the environment.  During inference, these
unification types are unfied with function type and, at
generalization, the remaining unification types are replaced by type
variables.  Hence, the "scheme" that remains for `f` and `g` are the
mono-types with free type variables.  (Similarly, the "scheme"
registered for `x`, `y`, and `z` are mono-types with free type
variables.)

To yield reasonable def-use extra information, these "schemes" are
pretty-printed with fresh local names for each distinct type
variable.  This makes each scheme look reasonable in isolation, but the
total information is not globally consistent.  For example, the
def-use information for the above program is:

    variable f z.sml 2.5 "'a -> 'b -> unit * 'b * 'a"
    variable x z.sml 2.8 "'a"
        z.sml 4.30
    variable y z.sml 2.16 "'a"
        z.sml 4.27
    variable g z.sml 4.11 "'a -> 'a * 'b * 'c"
        z.sml 6.7
    variable z z.sml 4.14 "'a"
        z.sml 4.24

Note that each of `x`, `y`, and `z` reports the type `'a`, despite the
fact that they must be distinct type variables.

This is probably better than the previous behavior (on this
branch) which would fall-thru to the default `Tyvar.layout` (with
gen-sym names):

    variable f z.sml 2.5 "'a_0 -> 'b_0 -> unit * 'b_0 * 'a_0"
    variable x z.sml 2.8 "'a_0"
        z.sml 4.30
    variable y z.sml 2.16 "'b_0"
        z.sml 4.27
    variable g z.sml 4.11 "'c_0 -> 'c_0 * 'b_0 * 'a_0"
        z.sml 6.7
    variable z z.sml 4.14 "'c_0"
        z.sml 4.24

While this information is globally consistent, in a full program,
with many inferred type variables, most polymorphic values have
schemes with `'a_2342`-style type variables, which are difficult
to read.

"Pretty" and "globally consistent" information would require some
effort.  In any case, this restores the (master branch) behavior
of `-keep-def-use`.
Clarify that only flexible tycons can have equality status changed.
In very rare circumstances, a flexible tycon may be referenced (and
displayed in a diagnostic) but not in scope (and not have a pretty
name set).  For example, consider the following program:

    datatype a = A
    signature T =
       sig
          type a = a
          type b
          type c
          type d
          type t = a * b * c * d -> unit
       end
    signature S =
       sig
          type a
          type c
          structure T1:
             sig
                structure T2 :
                   sig
                      type a
                      include T where type b = a
                                where type d = c
                   end
             end where type T2.t = unit
       end

Previously, MLton generated the error messages:

    Error: z.sml 19.27-20.44.
      Duplicate type specification: a.
        spec at: z.sml 18.24-18.24
        spec at: z.sml 4.12-4.12
    Error: z.sml 22.25-22.28.
      Type cannot be realized (defined): T2.t.
        type spec: type T2.t = ?.a
                               * ?.{admitsEquality = Never,
                                    creationTime = 132,
                                    hasCons = false,
                                    id = 9238,
                                    kind = 0}
                               * _sig.T2.c
                               * c
                               -> unit
        spec at: z.sml 8.12-8.12

At the `where type T2.t = unit`, the `type a` of `T2` has been shadowed
by the `include T`, although the flexible tycon `b` of `T` has been
realized as the shadowed `a`.

Now, MLton generates the following error messages:

    Error: z.sml 19.27-20.44.
      Duplicate type specification: a.
        spec at: z.sml 18.24-18.24
        spec at: z.sml 4.12-4.12
    Error: z.sml 22.25-22.28.
      Type cannot be realized (defined): T2.t.
        type spec: type T2.t = ?.a * ??.a * _sig.T2.c * c -> unit
        spec at: z.sml 8.12-8.12

Like shadowed tycons, a shadowed flexible tycon is displayed with a
default name (the name of the AST tycon that introduced it) prefixed
with "??".
Consider the following program:

    structure A =
       struct
          datatype a = A
          structure B =
             struct
                datatype b = B
             end
          val b = B.B
          structure B = struct end
          val _ : unit = b
       end
    signature T =
       sig
          type a = A.a
          type b
          type c
          type d
          type t = a * b * c * d -> unit
       end
    structure A = struct end
    signature S =
       sig
          type a
          type c
          structure T1:
             sig
                structure T2 :
                   sig
                      type a
                      include T where type b = a
                                where type d = c
                   end
             end where type T2.t = unit
       end

Now, MLton generates the following error messages:

    Error: z.sml 10.11-10.22.
      Pattern and expression disagree.
        pattern:    [unit]
        expression: [?.A.B.b]
        in: val _: unit = b
    Error: z.sml 30.27-31.44.
      Duplicate type specification: a.
        spec at: z.sml 29.24-29.24
        spec at: z.sml 14.12-14.12
    Error: z.sml 33.25-33.28.
      Type cannot be realized (defined): T2.t.
        type spec: type T2.t = ?.A.a * ??.S.T1.T2.a * _sig.T2.c * c -> unit
        spec at: z.sml 18.12-18.12

Note in the first error message that the default pretty name for a
shadowed tycon includes the structure in which it is being defined.
Now, in the last error message, the default pretty name for a flexible
tycon includes the signature in which it is being defined.
Previously, the last error message had "??.a" instead of
"??.S.T1.T2.a".
Consider the following program:

    signature T =
       sig
          type u
          type t
       end
    signature S =
       sig
          type u
          include T where type t = u -> u
       end
    structure S: S =
       struct
          type u = unit
          type t = u -> u
       end
    functor F (S: S): S = struct open S end

Previously, MLton generated an ICE:

    Error: z.sml 9.15-9.37.
      Duplicate type specification: u.
        spec at: z.sml 8.12-8.12
        spec at: z.sml 3.12-3.12
    unhandled exception: Fail: Interface.FlexibleTycon.realization

This occurs at the `structure S: S = ...` matching (and would occur
again at the creation of the dummy structure for the functor argument
and again at the "functor F (S: S): S = ...` result matching.  The
issue is that the shadowed `type u` in `signature S` is a flexible
tycon, but because it is shadowed, it is not reported as a flexible
tycon nor is it realized.  Nonetheless, the `type t` is realized as
`u -> u` for the shadowed `u`, which requires obtaining the
realization of the shadowed `u` to check the realized type of `t`.

Now, MLton generates the following error messages:

    Error: z.sml 9.15-9.37.
      Duplicate type specification: u.
        spec at: z.sml 8.12-8.12
        spec at: z.sml 3.12-3.12
    Error: z.sml 11.14-11.14.
      Type in structure disagrees with signature (type definition): t.
        structure: type t = [unit] -> [unit]
        defn at: z.sml 14.12-14.12
        signature: type t = [?.??.S.u] -> [?.??.S.u]
        spec at: z.sml 4.12-4.12
        spec at: z.sml 9.17-9.37
    Error: z.sml 16.19-16.19.
      Type in structure disagrees with signature (type definition): t.
        structure: type t = [?.??.S.u] -> [?.??.S.u]
        defn at: z.sml 4.12-4.12
        signature: type t = [?.??.S.u] -> [?.??.S.u]
        spec at: z.sml 4.12-4.12
        spec at: z.sml 9.17-9.37

It is difficult to give a good pretty name for this realization of a
shadowed flexible tycon, but it is also a rather obscure kind of error
and the "?.??." prefix seems to convey the difficulty.
Consider the following program:

    signature T =
       sig
          type u
          type t
       end
    signature S =
       sig
          type u
          include T where type t = u -> u
       end where type t = unit
    structure S:
       sig
          type u
          include T where type t = u -> u
       end =
       struct
          type u = unit
          type t = u -> u
       end
    functor F (type u
               include T where type t = u -> u):
       sig
          type u
          include T where type t = u -> u
       end =
       struct
          type u = u
          type t = t
       end
    functor G (X: sig
                     type u
                     include T where type t = u -> u
                  end):
       sig
          type u
          include T where type t = u -> u
       end =
       struct
          open X
       end

Now, MLton generates the following error messages:

    Error: z.sml 9.15-9.37.
      Duplicate type specification: u.
        spec at: z.sml 8.12-8.12
        spec at: z.sml 3.12-3.12
    Error: z.sml 10.19-10.19.
      Type cannot be realized (defined): t.
        type spec: type t = ??.S.u -> ??.S.u
        spec at: z.sml 4.12-4.12
        spec at: z.sml 9.17-9.37
    Error: z.sml 14.15-14.37.
      Duplicate type specification: u.
        spec at: z.sml 13.12-13.12
        spec at: z.sml 3.12-3.12
    Error: z.sml 12.4-15.6.
      Type in structure disagrees with signature (type definition): t.
        structure: type t = [unit] -> [unit]
        defn at: z.sml 18.12-18.12
        signature: type t = [?.??._sig.u] -> [?.??._sig.u]
        spec at: z.sml 4.12-4.12
        spec at: z.sml 14.17-14.37
    Error: z.sml 21.20-21.42.
      Duplicate type specification: u.
        spec at: z.sml 20.17-20.17
        spec at: z.sml 3.12-3.12
    Error: z.sml 24.15-24.37.
      Duplicate type specification: u.
        spec at: z.sml 23.12-23.12
        spec at: z.sml 3.12-3.12
    Error: z.sml 22.4-25.6.
      Type in structure disagrees with signature (type definition): t.
        structure: type t = [?.??._argF.u] -> [?.??._argF.u]
        defn at: z.sml 28.12-28.12
        signature: type t = [?.??._sig.u] -> [?.??._sig.u]
        spec at: z.sml 4.12-4.12
        spec at: z.sml 24.17-24.37
    Error: z.sml 32.26-32.48.
      Duplicate type specification: u.
        spec at: z.sml 31.23-31.23
        spec at: z.sml 3.12-3.12
    Error: z.sml 36.15-36.37.
      Duplicate type specification: u.
        spec at: z.sml 35.12-35.12
        spec at: z.sml 3.12-3.12
    Error: z.sml 34.4-37.6.
      Type in structure disagrees with signature (type definition): t.
        structure: type t = [?.??._argG.u] -> [?.??._argG.u]
        defn at: z.sml 4.12-4.12
        signature: type t = [?.??._sig.u] -> [?.??._sig.u]
        spec at: z.sml 4.12-4.12
        spec at: z.sml 36.17-36.37
Consider the following program:

    signature T = sig eqtype t end
    signature S = T where type t = (unit -> unit) * unit
    structure S: T = struct type t = (unit -> unit) * unit end

Previously, MLton generated the following error messages:

    Error: z.sml 2.17-2.52.
      Type cannot be realized (admits equality): t.
        type spec: [eqtype] t
        spec at: z.sml 1.26-1.26
        type defn: type t = [(unit -> unit) * unit]
    Error: z.sml 3.14-3.14.
      Type in structure disagrees with signature (admits equality): t.
        structure: type t = [_ -> _] * _
        defn at: z.sml 3.30-3.30
        signature: [eqtype] t
        spec at: z.sml 1.26-1.26

Note the different treatment of the non-equality type in "type cannot
be realized" and "type in structure disagrees with signature".

Now, MLton generates the following error messages:

    Error: z.sml 2.17-2.52.
      Type cannot be realized (admits equality): t.
        type spec: [eqtype] t
        spec at: z.sml 1.26-1.26
        type defn: type t = [_ -> _] * _
    Error: z.sml 3.14-3.14.
      Type in structure disagrees with signature (admits equality): t.
        structure: type t = [_ -> _] * _
        defn at: z.sml 3.30-3.30
        signature: [eqtype] t
        spec at: z.sml 1.26-1.26
Consider the following program:

    signature S =
       sig
          eqtype u
          type t
          sharing type t = u
       end where type t = unit -> unit

Previously, MLton generated the following error message:

    Error: z.sml 6.8-6.34.
      Type cannot be realized (admits equality): t.
        type spec: type t = [_sig.u]
        spec at: z.sml 4.12-4.12
        spec at: z.sml 5.7-5.24
        type defn: type t = [_ -> _]

The specs include the "type t" and the "sharing type t = u", but not
the "eqtype t" which establishes the equality typeness.

Now, MLton generates the following error message:

    Error: z.sml 6.8-6.34.
      Type cannot be realized (admits equality): t.
        type spec: type t = [_sig.u]
        spec at: z.sml 4.12-4.12
        spec at: z.sml 3.14-3.14
        spec at: z.sml 5.7-5.24
        type defn: type t = [_ -> _]
Consider the following program:

    val id: 'a -> 'a = fn x => x
    val f: 'a -> 'a = id id
    val g = id (fn (x: 'a) => x)

    val _ = (f 1, f true)

Previously, MLton generated the following diagnostics:

    Error: z.sml 2.5-2.5.
      Type of variable cannot be generalized in expansive declaration: f.
        type: ['a] -> ['a]
        in: val 'a f: ('a -> 'a) = id id
    Error: z.sml 3.5-3.5.
      Type of variable cannot be generalized in expansive declaration: g.
        type: ['a] -> ['a]
        in: val 'a g = id (fn x: 'a => x)
    Error: z.sml 5.15-5.20.
      Function applied to incorrect argument.
        expects: [int]
        but got: [bool]
        in: f true
    Warning: z.sml 3.5-3.5.
      Type of variable was not inferred and could not be generalized: g.
        type: ??? -> ???
        in: val 'a g = id (fn x: 'a => x)

Taking the type annotation on `f` as the user's intention, the
subsequent type error at the application `f true` is spurious.

Now, MLton generates the following diagnostics:

    Error: z.sml 2.5-2.5.
      Type of variable cannot be generalized in expansive declaration: f.
        type: ['a] -> ['a]
        in: val 'a f: ('a -> 'a) = id id
    Error: z.sml 3.5-3.5.
      Type of variable cannot be generalized in expansive declaration: g.
        type: ['a] -> ['a]
        in: val 'a g = id (fn x: 'a => x)
@MatthewFluet MatthewFluet merged commit 505a23c into MLton:master Oct 6, 2017
@MatthewFluet MatthewFluet deleted the diagnostic-messages branch October 6, 2017 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant