Last modified: 2009-06-05 17:16:53 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T21093, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 19093 - Counterintuitive restrictions on position of #default case in #switch:
Counterintuitive restrictions on position of #default case in #switch:
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
ParserFunctions (Other open bugs)
unspecified
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-06-05 15:04 UTC by Happy-melon
Modified: 2009-06-05 17:16 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Happy-melon 2009-06-05 15:04:41 UTC
Enter:

<{{#switch: foo | bar = bar | #default | baz = quok }}>

Expected: 

<quok>

Actual:

<>

The #default delimiter is only recognised as such if it is the last in a duplicate stack.
Comment 1 Niklas Laxström 2009-06-05 15:22:59 UTC
That's how it is in all programming languages I know.
Comment 2 Andrew Garrett 2009-06-05 15:26:58 UTC
(In reply to comment #0)
> Enter:
> 
> <{{#switch: foo | bar = bar | #default | baz = quok }}>
> 
> Expected: 
> 
> <quok>
> 
> Actual:
> 
> <>

I'm confused, <> should be expected, because 'foo' doesn't have its own entry. Perhaps you mean #switch: baz
Comment 3 Aryeh Gregor (not reading bugmail, please e-mail directly) 2009-06-05 15:36:46 UTC
<{{#switch: foo | bar = bar | #default = quuz | baz = quok }}>

outputs <quuz> as expected.  WORKSFORME.

(In reply to comment #1)
> That's how it is in all programming languages I know.

$ echo '<?php switch(1) { default: echo "default\n"; break; case 2: echo "2\n"; break; }' | php
default

Also probably not in C.  Why would such a restriction exist?
Comment 4 Happy-melon 2009-06-05 15:40:20 UTC
Wow, edit conflicts on bugzilla!  

But as we're all so fond of saying, wikimarkup is not a programming language :P

The clear intention for the layman is for the "#default" to act as a marker for
'none of the above' (or indeed 'none of the below' as the #default case doesn't
have to be the last in the sequence).  If we replaced "#default" by "foo" in
the example, then we'd get 

<{{#switch: foo | bar = bar | foo | baz = quok }}> --> <quok> 

as expected.  The implication of the "#default" marker is that it *always*
matches the test string, unless another explicit marker matches.  The
bug is that this universal-matching is position-dependent:

<{{#switch: foo  | bar | baz = ABC | #default = DEF }}> --> <DEF>
<{{#switch: foo  | bar | #default = DEF | baz = ABC }}> --> <DEF>
<{{#switch: foo  | #default | bar = DEF | baz = ABC }}> --> <>

That doesn't look very intuitive to me.
Comment 5 Andrew Garrett 2009-06-05 15:43:44 UTC
(In reply to comment #4)
> <{{#switch: foo  | bar | baz = ABC | #default = DEF }}> --> <DEF>
> <{{#switch: foo  | bar | #default = DEF | baz = ABC }}> --> <DEF>
> <{{#switch: foo  | #default | bar = DEF | baz = ABC }}> --> <>
> 
> That doesn't look very intuitive to me.

Those test cases differ in more than position.

The first two don't differ except for position, and they give the same output.

The first two differ from the last test case in that the DEF has been moved from #default to bar, and therefore you get a different result.

Where's the bug?

Comment 6 Aryeh Gregor (not reading bugmail, please e-mail directly) 2009-06-05 15:44:51 UTC
(In reply to comment #5)
> Those test cases differ in more than position.
> 
> The first two don't differ except for position, and they give the same output.
> 
> The first two differ from the last test case in that the DEF has been moved
> from #default to bar, and therefore you get a different result.
> 
> Where's the bug?

The syntax {{#switch: foo | bar | baz=quuz}} is supposed to be equivalent to {{#switch: foo | bar=quuz | baz=quuz}}.  I.e., we support a kind of fallthrough, but it only worked for named parameters, not #default.  He's right, this is a bug.
Comment 7 Aryeh Gregor (not reading bugmail, please e-mail directly) 2009-06-05 17:16:53 UTC
Fixed in r51509 and r51511.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links