[m-rev.] diff: fix bug in error messages
Julien Fischer
juliensf at cs.mu.OZ.AU
Thu May 19 14:58:08 AEST 2005
On Thu, 19 May 2005, Mark Brown wrote:
> On 19-May-2005, Julien Fischer <juliensf at cs.mu.OZ.AU> wrote:
> >
> > On Sun, 8 May 2005, Mark Brown wrote:
> >
> > > Hi,
> > >
> > > This fixes a bug that was reported by Rob Moss a while ago.
> > >
> > > Cheers,
> > > Mark.
> > >
> > > Estimated hours taken: 0.5
> > > Branches: main, release
> > >
> > > compiler/module_qual.m:
> > > Check for variables used as constructors when module qualifying types
> > > and insts. In both cases this is currently illegal, so we report a
> > > more sensible error message than we would otherwise get.
> > >
> > > compiler/prog_type.m:
> > > Export a test to check if a type uses a variable as a constructor.
> > >
> > > tests/invalid/Mmakefile:
> > > tests/invalid/kind.err_exp:
> > > tests/invalid/kind.m:
> > > Test case.
> > >
> >
> > This change has broken code like that in the attached example where
> > we define a type like the following:
> >
> > :- type '' ---> ''.
> >
> > and then try to use it.
>
> Hmm. It also "breaks" the following code:
>
> :- type ''(T) ---> f(T).
> :- func bar(int) = ''(int).
> bar(N) = f(N).
>
> But this code should be illegal, since according to the reference manual:
>
> | A higher-order term is equivalent to a simple compound term whose functor
> | is the empty name, and whose arguments are the closure term followed by
> | the argument terms of the higher-order term.
>
> therefore the definition of baz is equivalent to:
>
> :- func baz(int) = int.
> baz(N) = g(N).
>
> which is a type error.
>
> It also breaks:
>
> :- type ''(T, U) ---> g(T, U).
> :- func baz(int) = ''(int, int).
> baz(N) = g(N, N).
>
> Here the definition of baz is equivalent to:
>
> :- func baz(int) = int(int).
> baz(N) = g(N, N).
>
> which doesn't make sense at all.
>
> (Note that the error reported for the bar/1 case is wrong, since the
> compiler objects to the type expression ''(int) but does not object to
> the type definition for ''(T). The error message for baz/1 is okay.)
>
> So the question is, should
>
> :- type '' ---> ''.
>
> be legal? In value expressions the term '' is a builtin that is is
> equivalent to 'apply', since it takes the first (higher-order) argument
> and applies the remaining arguments. When we have higher order types
> (i.e. constructor classes, etc), the type expression '' should be the
> type equivalent of 'apply'.
>
> So I think the answer to the question is no, the above type should not
> be legal, and the funny_type test case should be changed or removed.
>
There is no funny_type test case to change or remove; it was just
an example of the problem. What will need to be changed is the
code in extras/xml, where the example was orginally taken from.
> Are there any dissenting views?
Not from me.
> If not, I shall look into fixing the
> errors that are reported, and also clarifying the reference manual.
>
Does this also mean that the following will also be illegal?
:- type bar ---> ''.
Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list