Files
mercury/tests/invalid/bug191.m
Julien Fischer f45a1a8967 Report an error for a type class with no parameters.
The compiler was not rejecting typeclass declarations without any class
parameters, for example:

    :- typeclass foo where [].

Mercury requires typeclass declarations to have at least one class parameter.

compiler/prog_io_typeclass.m:
    Emit an error if we encounter a typeclass declaration with no parameters.

tests/invalid/Mmakefile:
tests/invalid/typeclass_no_param.{m,err_exp:
    Add a regression test for the above.

tests/invalid/bug191.{m,err_exp}:
    Avoid having a typeclass with no parameters.
2015-11-04 20:12:11 +11:00

33 lines
728 B
Mathematica

% Regression test for bug #191:
% This program caused the following compiler abort in rotd-2011-03-22:
%
% Software Error: code_gen.m: Unexpected: semidet model in det context
%
:- module bug191.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- type foo ---> a(int); b(string).
:- inst a ---> a(ground).
:- typeclass foo(T) where [pred baz(T::in, int::in, foo::out(a)) is det].
:- instance foo(int) where [pred(baz/3) is bar].
:- pred foo(foo::in(a), int::out) is det.
foo(a(I), I).
% should be bar(int::in, foo::out(a))
:- pred bar(int::in, int::in, foo::out) is det.
bar(_, _S, b("GOTCHA")).
main(!IO) :-
baz(561, 42, F),
foo(F, I),
print(I, !IO), nl(!IO).