Received: from eggs.gnu.org ([2001:4830:134:3::10]:40037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWRyy-000251-8w for qemu-devel@nongnu.org; Thu, 18 Feb 2016 12:03:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWRyv-0005M8-0u for qemu-devel@nongnu.org; Thu, 18 Feb 2016 12:03:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45757) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWRyu-0005LZ-SL for qemu-devel@nongnu.org; Thu, 18 Feb 2016 12:03:08 -0500 From: Markus Armbruster References: <1455778109-6278-1-git-send-email-eblake@redhat.com> <1455778109-6278-4-git-send-email-eblake@redhat.com> <87si0qgr5u.fsf@blackfin.pond.sub.org> <56C5D7C8.1020701@redhat.com> Date: Thu, 18 Feb 2016 18:03:05 +0100 In-Reply-To: <56C5D7C8.1020701@redhat.com> (Eric Blake's message of "Thu, 18 Feb 2016 07:40:08 -0700") Message-ID: <87povu7xyu.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v11 03/15] qapi: Forbid 'any' inside an alternate List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org, Michael Roth Eric Blake writes: > On 02/18/2016 05:05 AM, Markus Armbruster wrote: >> Eric Blake writes: >> >>> The whole point of an alternate is to allow some type-safety while >>> still accepting more than one JSON type. Meanwhile, the 'any' >>> type exists to bypass type-safety altogether. The two are >>> incompatible: you can't accept every type, and still tell which >>> branch of the alternate to use for the parse; fix this to give a >>> sane error instead of a Python stack trace. >>> >>> Signed-off-by: Eric Blake >>> > >> >> Interestingly, find_alternate_member_qtype(T) can return None in two >> ways: when builtin_types[T] is None (only for T == 'any'), and when T is >> neither built-in, struct, enum or union (it must be alternate then). >> >> This leads to the question whether this patch catches exactly 'any', as >> the commit message claims, or alternate as well. >> > >>> >>> @@ -629,7 +629,10 @@ def check_alternate(expr, expr_info): >>> value, >>> allow_metas=['built-in', 'union', 'struct', 'enum']) >>> qtype = find_alternate_member_qtype(value) >> > >> >> Could use a test for alternate member of alternate type. > > One step ahead of you: commit 3d0c4829 added the test > alternate-nested.json, and commits 44bd1276 and dd883c6f fixed the > parser to reject it (first by a hard-coded check, then via allow_metas[] > excluding alternates). 'any' is the only value that could sneak > through, because it is a subset of 'built-in' which allow_metas[] > whitelisted. Then find_alternate_member_qtype()'s final return None is unreachable, correct? > If you want to squash any of this information into the commit message, > though, I don't mind. I'll consider it when I apply.