mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 14:57:03 +00:00
Estimated hours taken: 2 Branches: main, release-0.12 Only allow existential constraints to constrain existentially quantified type variables. Likewise only allow universal constraints to constrain universally quantified type variables. We previously didn't check these conditions, and in fact the reference manual allowed otherwise. However, the implementation did not support existential constraints on universally quantified type variables, and will not do so for the foreseeable future. The implementation does support universal constraints on existentially quantified variables, however these are not useful since no caller will ever be able to satisfy the constraints. compiler/check_typeclass.m: Check these conditions as part of typeclass checking. Also return a bool from the recently added check for concrete instances, indicating whether errors were found or not. compiler/error_util.m: compiler/hlds_error_util.m: Add a couple of utility functions for constructing error messages. compiler/mercury_compile.m: Stop compilation after checking typeclasses if errors were encountered. If the above conditions are not met then typechecking may abort. doc/reference_manual.texi: Document the condition on typeclass constraints. tests/invalid/Mmakefile: tests/invalid/quant_constraint_1.err_exp: tests/invalid/quant_constraint_1.m: tests/invalid/quant_constraint_2.err_exp: tests/invalid/quant_constraint_2.m: Test cases for the new error messages. tests/invalid/unbound_type_vars.err_exp: Update this test case.
25 lines
364 B
Mathematica
25 lines
364 B
Mathematica
:- module quant_constraint_2.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- typeclass c1(T1) where [].
|
|
|
|
% Error: T is existentially quantified, but appears in a universal
|
|
% constraint.
|
|
%
|
|
:- some [T] (func q = T <= c1(T)).
|
|
|
|
:- implementation.
|
|
|
|
:- instance c1(int) where [].
|
|
|
|
q = 1.
|
|
|
|
main(!IO) :-
|
|
X = q,
|
|
write(X, !IO),
|
|
nl(!IO).
|
|
|