Files
mercury/tests/invalid/char_inst.m
Zoltan Somogyi 6229771305 Propagate type char into bound_insts.
compiler/mode_util.m:
    As above. This is needed to allow the compiler to check whether
    a char constant matches an inst that is specific to the char type.

tests/invalid/char_inst.{m,err_exp}:
    A new test case for the fixed functionality.

tests/invalid/Mmakefile:
    Enable the new test case.
2021-06-08 07:57:52 +10:00

37 lines
852 B
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module char_inst.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module char.
main(!IO) :-
test('s', !IO), % This should be accepted without complaint.
test('x', !IO). % This should generate an error message.
:- inst key_char for char/0
---> ('s')
; ('i')
; ('f').
:- pred test(char::in(key_char), io::di, io::uo) is det.
test(KeyChar, !IO) :-
(
KeyChar = 's',
io.write_string("string\n", !IO)
;
KeyChar = 'i',
io.write_string("int\n", !IO)
;
KeyChar = 'f',
io.write_string("float\n", !IO)
).