mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 03:43:51 +00:00
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.
37 lines
852 B
Mathematica
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)
|
|
).
|