%---------------------------------------------------------------------------% % vim: ft=mercury ts=4 sw=4 et %---------------------------------------------------------------------------% % % This is cut-down version of the colipa program by Volker Wysk sent to m-rev % on 3 January 2024. % % Reference: % https://lists.mercurylang.org/archives/reviews/2024-January/024517.html % % Compiling in a debug grade, results in: % % Uncaught Mercury exception: % Software Error: predicate `ll_backend.liveness.require_equal'/4: % Unexpected: branches of if-then-else disagree on liveness % First: ArgDesc_3, Values_4, MDef_5, Default_6, % TypeClassInfo_for_argument_21, TypeInfo_22_22 % Rest: ArgDesc_3, Values_4, MDef_5, Default_6, TypeInfo_22_22 % % Compilation in non-debug grades succeeds. % %---------------------------------------------------------------------------% :- module bug572. :- interface. :- import_module list. :- import_module string. %---------------------------------------------------------------------------% :- type cla ---> cla(string). :- typeclass argument(T) where []. :- type argdesc. %---------------------------------------------------------------------------% :- pred get_from_default(argdesc::in, list(T)::out) is det <= argument(T). %---------------------------------------------------------------------------% %---------------------------------------------------------------------------% :- implementation. :- import_module map. :- import_module maybe. :- import_module exception. :- import_module type_desc. %---------------------------------------------------------------------------% %---------------------------------------------------------------------------% :- type argdesc ---> some [T] argdesc( argdesc_default :: maybe(T) ). %---------------------------------------------------------------------------% get_from_default(ArgDesc, Values) :- MDef = ArgDesc ^ argdesc_default, ( MDef = yes(Default), ( if private_builtin.typed_unify(Default, Val0) then Values = [Val0] else ValuesTypeDesc = type_of(Values), type_ctor_and_args(ValuesTypeDesc, _, TArgs), ( TArgs = [_], throw("mismatch") ; TArgs = [], throw("no type args") ; TArgs = [_, _ | _], throw("too many type args") ) ) ; MDef = no, Values = [] ). %---------------------------------------------------------------------------%