diff: fix bug for ambiguous qualified func
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Feb 19 14:16:29 AEDT 1998
Estimated hours taken: 0.75
compiler/modecheck_unify.m:
Fix a bug which caused the compiler to generate incorrect
code for the case where a function had the same name and arity
as a data constructor (but a different return type),
and the data constructor was used with an explicit module
qualifier -- it incorrectly ignored the types and chose
the function rather than the data constructor.
tests/hard_coded/Mmakefile:
tests/hard_coded/func_ctor_ambig.m:
tests/hard_coded/func_ctor_ambig.exp:
Regression test.
cvs diff compiler/modecheck_unify.m tests/hard_coded/Mmakefile tests/hard_coded/func_ctor_ambig.exp tests/hard_coded/func_ctor_ambig.m
Index: compiler/modecheck_unify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.31
diff -u -r1.31 modecheck_unify.m
--- modecheck_unify.m 1998/02/15 21:12:09 1.31
+++ modecheck_unify.m 1998/02/19 03:02:34
@@ -169,27 +169,19 @@
%
\+ code_util__compiler_generated(PredInfo),
- (
- PredName = unqualified(UnqualPName),
- predicate_table_search_func_name_arity(PredTable,
- UnqualPName, Arity, PredIds),
-
- % Check if there any of the candidate functions,
- % have argument/return types which subsume the actual
- % argument/return types of this function call
-
- pred_info_typevarset(PredInfo, TVarSet),
- map__apply_to_list(ArgVars0, VarTypes0, ArgTypes0),
- list__append(ArgTypes0, [TypeOfX], ArgTypes),
- typecheck__find_matching_pred_id(PredIds, ModuleInfo0,
- TVarSet, ArgTypes, PredId, QualifiedFuncName)
- ;
- PredName = qualified(FuncModule, UnqualName),
- predicate_table_search_func_m_n_a(PredTable,
- FuncModule, UnqualName, Arity, [PredId]),
- QualifiedFuncName = PredName
- )
+ predicate_table_search_func_sym_arity(PredTable,
+ PredName, Arity, PredIds),
+
+ % Check if any of the candidate functions have
+ % argument/return types which subsume the actual
+ % argument/return types of this function call
+
+ pred_info_typevarset(PredInfo, TVarSet),
+ map__apply_to_list(ArgVars0, VarTypes0, ArgTypes0),
+ list__append(ArgTypes0, [TypeOfX], ArgTypes),
+ typecheck__find_matching_pred_id(PredIds, ModuleInfo0,
+ TVarSet, ArgTypes, PredId, QualifiedFuncName)
->
%
% Convert function calls into predicate calls:
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.16
diff -u -r1.16 Mmakefile
--- Mmakefile 1998/02/05 02:51:15 1.16
+++ Mmakefile 1998/02/19 03:13:27
@@ -31,6 +31,7 @@
float_rounding_bug \
free_free_mode \
func_and_pred \
+ func_ctor_ambig \
func_test \
getopt_test \
ground_dd \
Index: tests/hard_coded/func_ctor_ambig.exp
===================================================================
RCS file: func_ctor_ambig.exp
diff -N func_ctor_ambig.exp
--- /dev/null Thu Feb 19 14:14:17 1998
+++ func_ctor_ambig.exp Thu Feb 19 14:13:03 1998
@@ -0,0 +1,4 @@
+bar = 42
+bar2 = 42
+baz = ambig
+baz2 = ambig
Index: tests/hard_coded/func_ctor_ambig.m
===================================================================
RCS file: func_ctor_ambig.m
diff -N func_ctor_ambig.m
--- /dev/null Thu Feb 19 14:14:17 1998
+++ func_ctor_ambig.m Thu Feb 19 14:14:52 1998
@@ -0,0 +1,35 @@
+% Mercury 0.7.3 generated incorrect code for this test case.
+
+:- module func_ctor_ambig.
+:- interface.
+:- import_module io.
+
+:- type t.
+:- func bar = int.
+:- func baz = t.
+:- func bar2 = int.
+:- func baz2 = t.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+main -->
+ print("bar = "), print(bar), nl,
+ print("bar2 = "), print(bar2), nl,
+ print("baz = "), print(baz), nl,
+ print("baz2 = "), print(baz2), nl.
+
+:- type t ---> ambig.
+
+:- func ambig = int.
+ambig = 42.
+
+bar = ambig.
+
+baz = ambig.
+
+bar2 = func_ctor_ambig:ambig.
+
+baz2 = func_ctor_ambig:ambig.
+
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list