[m-rev.] diff: fix bug in record syntax
Simon Taylor
stayl at cs.mu.OZ.AU
Tue Oct 2 23:58:04 AEST 2001
Estimated hours taken: 1
Branches: main, release
compiler/post_typecheck.m:
Fix a bug in record syntax. Existentially quantified type
variables which occurred in the field being extracted and
in other fields of the constructor were not being substituted
correctly in the types of the other fields, resulting in an
abort in polymorphism.m.
tests/valid/Mmakefile:
tests/valid/record_syntax_bug_5.m:
Test case.
Index: compiler/post_typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/post_typecheck.m,v
retrieving revision 1.33
diff -u -u -r1.33 post_typecheck.m
--- compiler/post_typecheck.m 5 Sep 2001 09:10:07 -0000 1.33
+++ compiler/post_typecheck.m 2 Oct 2001 13:47:55 -0000
@@ -1226,7 +1226,34 @@
ConsId, FieldNumber),
get_cons_id_arg_types_adding_existq_tvars(ModuleInfo, ConsId,
- TermType, ArgTypes, _, PredInfo0, PredInfo),
+ TermType, ArgTypes0, ExistQVars, PredInfo0, PredInfo),
+
+ %
+ % If the type of the field we are extracting contains existentially
+ % quantified type variables then we need to rename any other
+ % occurrences of those type variables in the arguments of the
+ % constructor so that they match those in the type of the field.
+ % (We don't need to do this for field updates because if any
+ % existentially quantified type variables occur in field to set
+ % and other fields then the field update should have been disallowed
+ % by typecheck.m because the result can't be well-typed).
+ %
+ ( ExistQVars \= [] ->
+ map__lookup(VarTypes0, FieldVar, FieldType),
+ list__index1_det(ArgTypes0, FieldNumber, FieldArgType),
+ (
+ type_list_subsumes([FieldArgType], [FieldType],
+ FieldSubst)
+ ->
+ term__apply_rec_substitution_to_list(ArgTypes0,
+ FieldSubst, ArgTypes)
+ ;
+ error(
+ "post_typecheck__translate_get_function: type_list_subsumes failed")
+ )
+ ;
+ ArgTypes = ArgTypes0
+ ),
split_list_at_index(FieldNumber, ArgTypes,
TypesBeforeField, _, TypesAfterField),
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.91
diff -u -u -r1.91 Mmakefile
--- tests/valid/Mmakefile 13 Sep 2001 23:18:17 -0000 1.91
+++ tests/valid/Mmakefile 2 Oct 2001 11:08:55 -0000
@@ -136,6 +136,7 @@
record_syntax_bug_2.m \
record_syntax_bug_3.m \
record_syntax_bug_4.m \
+ record_syntax_bug_5.m \
recursive_no_tag_type.m \
same_length_2.m \
semidet_disj.m \
Index: tests/valid/record_syntax_bug_5.m
===================================================================
RCS file: tests/valid/record_syntax_bug_5.m
diff -N tests/valid/record_syntax_bug_5.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/valid/record_syntax_bug_5.m 2 Oct 2001 11:09:35 -0000
@@ -0,0 +1,11 @@
+:- module record_syntax_bug_5.
+:- interface.
+
+:- type t ---> some[T] functor(a :: T, b :: T).
+
+:- some [T] func foo(t) = T.
+
+:- implementation.
+
+foo(Z) = Z^b.
+
--------------------------------------------------------------------------
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