[MLton] front-end functor bug

Stephen Weeks MLton@mlton.org
Fri, 6 Feb 2004 19:12:59 -0800

> I've encountered a front-end bug with the Moby sources; unfortunately I
> can't boil it down to a smaller example

Here's a small example that shows the problem.

functor F () =
      val A = 0
structure S =
      datatype z = A
      structure F = F ()

>    a) a functor RegisterAllocator includes the following declarations in
>       its body:
> 	   val SPILL_COALESCING       = 0wx100
> 	   val SPILL_COLORING         = 0wx200
>    Now, when compiling the program, I get errors like:
> 	Error: z.sml 18294.7: pattern and expression disagree
> 	   pattern:    [raPhase]
> 	   expression: [mode]
> 	   in: SPILL_COLORING = 0wx200
>    which appears to indicate that SPILL_COLORING is being granted
>    constructor status, despite the fact that this declaration corresponds
>    to (a).

Yep, that's the problem.  There was a bug in the implementation of
functor closures that forgot to "zero out" the constructors before
re-elaborating the functor body.  You would only ever see it if the
constructor was not in scope at the functor definition.

I've checked in a fix.