Fix a bug reported by Peter Ross.

Estimated hours taken: 6
Branches: main, release

Fix a bug reported by Peter Ross.

compiler/typeclasses.m:
	When recovering after an unsatisfiable constraint, don't merely
	delete the existing unproven constraints.  Instead construct new
	hlds_constraints from scratch.  This ensures that the invariants
	on it are maintained.

tests/invalid/Mmakefile:
tests/invalid/unsatisfiable_constraint_bug.err_exp:
tests/invalid/unsatisfiable_constraint_bug.m:
	Regression test.
This commit is contained in:
Mark Brown
2006-11-21 11:47:49 +00:00
parent 1b53e0d135
commit 1c0b5fd8a8
4 changed files with 49 additions and 3 deletions

View File

@@ -126,10 +126,13 @@ perform_context_reduction(OrigTypeAssignSet, !Info) :-
Spec = report_unsatisfiable_constraints(!.Info, TypeAssignSet0),
typecheck_info_add_error(Spec, !Info),
DeleteConstraints = (pred(TA0::in, TA::out) is det :-
% Make a new hlds_constraints structure for the type assign,
% with the same assumed constraints but all unproven constraints
% deleted.
type_assign_get_typeclass_constraints(TA0, Constraints0),
Constraints = (Constraints0
^ unproven := [])
^ redundant := multi_map.init,
type_assign_get_typevarset(TA0, TVarSet),
make_hlds_constraints(ClassTable, TVarSet, [],
Constraints0 ^ assumed, Constraints),
type_assign_set_typeclass_constraints(Constraints, TA0, TA)
),
list.map(DeleteConstraints, OrigTypeAssignSet, NewTypeAssignSet),

View File

@@ -209,6 +209,7 @@ SINGLEMODULE= \
uniq_mutable \
uniq_neg \
unsatisfiable_constraint \
unsatisfiable_constraint_bug \
unsatisfiable_super \
user_eq_dummy \
uu_type \

View File

@@ -0,0 +1,9 @@
unsatisfiable_constraint_bug.m:023: In clause for predicate `test_stream'/5:
unsatisfiable_constraint_bug.m:023: unsatisfiable typeclass constraint:
unsatisfiable_constraint_bug.m:023: `stream.writer(S, float, B)'.
unsatisfiable_constraint_bug.m:025: In clause for predicate `test_stream'/5:
unsatisfiable_constraint_bug.m:025: unsatisfiable typeclass constraint:
unsatisfiable_constraint_bug.m:025: `stream.reader(S, float, B, E)'.
unsatisfiable_constraint_bug.m:026: In clause for predicate `test_stream'/5:
unsatisfiable_constraint_bug.m:026: unsatisfiable typeclass constraint:
unsatisfiable_constraint_bug.m:026: `stream.reader(S, float, State, E)'.

View File

@@ -0,0 +1,33 @@
% The code caused the compiler the abort, rather than report an error
% for the unsatisfiable constraints.
% Software Error: map.lookup: key not found
% Key Type: term.var(parse_tree.prog_data.prog_var_type)
% Key Value: var(6)
% Value Type: parse_tree.prog_data.mer_type
:- module unsatisfiable_constraint_bug.
:- interface.
:- import_module io.
:- import_module stream.
:- pred test_stream(S::in, B::di, B::uo, io::di, io::uo) is det
<= (reader(S, int, B, E), writer(S, int, B)).
% XXX add these two lines and the program compiles
% reader(S, float, B, E), writer(S, float, B)).
:- implementation.
test_stream(S, !Buffer, !IO) :-
stream.put(S, 10, !Buffer),
stream.put(S, 3.14, !Buffer),
stream.get(S, ResultA : stream.result(int, E), !Buffer),
stream.get(S, ResultB : stream.result(float, E), !Buffer),
stream.get(S, ResultC : stream.result(float, E), !Buffer),
io.write(ResultA, !IO),
io.nl(!IO),
io.write(ResultB, !IO),
io.nl(!IO),
io.write(ResultC, !IO),
io.nl(!IO).