mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 07:15:19 +00:00
For review by anyone. Estimated hours taken: 10 Branches: main, release Do not allow non-abstract instance declarations to occur in module interfaces. Emit an error message if this occurs. Fix the formatting of some error messages regarding typeclasses and instances. compiler/check_typeclass.m: Use error_util to generate the error messages from this module. This fixes a problem where the printing of sym_names and arities differed in the same error message. compiler/error_util.m: Add a format component for the pred_or_func type. Add the equivalence type format_components. compiler/make_hlds.m: Make the format of some error messages concerning typeclasses more consistent. compiler/modules.m: Check for non-abstract instance declarations in module interfaces and emit an error message if they do. tests/invalid/Mmakefile: tests/invalid/instance_bug.m: tests/invalid/instance_bug.err_exp: Test case for the above. tests/hard_coded/typeclasses/*: tests/invalid/*: tests/recompilation/*: tests/valid/*: Update test cases as necessary.
34 lines
672 B
Mathematica
34 lines
672 B
Mathematica
:- module impure_method_impl.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- typeclass c(T) where [
|
|
pred m1(T::in, int::out) is det,
|
|
semipure pred m2(T::in, int::out) is det
|
|
].
|
|
|
|
:- type foo ---> foo.
|
|
|
|
:- semipure pred foo_m1(foo::in, int::out) is det.
|
|
:- impure pred foo_m2(foo::in, int::out) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- instance c(foo) where [
|
|
pred(m1/2) is foo_m1,
|
|
pred(m2/2) is foo_m2
|
|
].
|
|
|
|
main -->
|
|
[].
|
|
|
|
:- pragma c_header_code("int foo_counter = 0;").
|
|
|
|
:- pragma c_code(foo_m1(_F::in, Val::out), "Val = foo_counter;").
|
|
:- pragma c_code(foo_m2(_F::in, Val::out), "Val = foo_counter++;").
|
|
foo_m1(_, 0).
|
|
foo_m2(_, 0).
|