Files
mercury/tests/invalid/int_ops.m
Zoltan Somogyi 01836315ac Specialize diagnostics for numeric operations.
compiler/typecheck_error_undef.m:
    When users try to use arithmetic operations, bitwise operations,
    or comparisons (meaning functions such as '+' or '<<', or predicates
    such as '<') without importing any of the modules that define those ops,
    generate a diagnostic that explains this specific situation. Mercury
    is unusual in requiring such imports, so novices need to have this
    pointed out to them. Have these messages replace the less-specific
    messages we used to generate in such situations.

    Fix a persistent typo.

tests/invalid/int_ops.{m,err_exp}:
    A new test case for the new diagnostics.

tests/invalid/Mmakefile:
    Enable the new test case.

tests/invalid/multiply_star.err_exp:
    Expect the diagnostic text, and stop expecting the "did you mean"
    message that it replaces.

tests/invalid/multiply_star.err_exp[23]:
    Delete these files. They existed only because different sets of imports
    with different options yielded different "did you mean" suggestions,
    and we don't have those anymore.

tests/invalid/multiply_star.m:
    Update the descriptions of the deleted .err_exp[23] files.
2025-11-02 16:25:59 +11:00

29 lines
790 B
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% This test case extends and effectively replaces the old multiply_star
% test case.
%
%---------------------------------------------------------------------------%
:- module int_ops.
:- interface.
:- pred p(int::in, int::out) is det.
:- implementation.
% :- import_module int. % This import is missing.
p(A, Z) :-
( if A < 0 then % comparison
Z = A << 3 % bitwise operation
else if A >= 2 then % comparison
Z = A * 2 % int and float arithmetic
else
Z = A // 2 % int only arithmetic
).