Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 8bdba0dc555d434a61040d8cfdf6fc7167cfe6c6b32cea397572620ce70a1b4b
Ticket: 8f741de59dbc79b0d6e1b71abe338391081492f5
switch compilation difference with end of opts marker
User & Date: juliannoble2 on 2025-11-10 08:47:37
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-plain"
  4. comment changed to:
    The below comment block in tclCompCmdSz.c suggests the intention is for 
    
    switch -exact    word {pattern body ...}
    to be treated the same as
    switch -exact -- word {pattern body ...}
    
    as far as compilation is concerned.
    Similarly for -glob and -regexp
    
    However, the -- seems to be required for the compilation to proceed
    as after the option processing loop we have:
        if (numWords < 3) {
    	return TCL_ERROR;
        }
    
    
    #comments from tclCompCmdsSZ.c TclCompileSwitchCmd
    
    #    /*
    #     * Only handle the following versions:
    #     *   switch         ?--? word {pattern body ...}
    #     *   switch -exact  ?--? word {pattern body ...}
    #     *   switch -glob   ?--? word {pattern body ...}
    #     *   switch -regexp ?--? word {pattern body ...}
    #     *   switch         --   word simpleWordPattern simpleWordBody ...
    #     *   switch -exact  --   word simpleWordPattern simpleWordBody ...
    #     *   switch -glob   --   word simpleWordPattern simpleWordBody ...
    #     *   switch -regexp --   word simpleWordPattern simpleWordBody ...
    #     * When the mode is -glob, can also handle a -nocase flag.
    #     *
    #     * First off, we don't care how the command's word was generated; we're
    #     * compiling it anyway! So skip it...
    #     */
    
    
    It is verifiable with tcl::unsupported::disassemble that (for the combined pattern body versions)
    switch -exact     word {pattern body ...}
    compiles differently to
    switch -exact --  word {pattern body ...}
    (as with -glob and -exact)
    
    Is this intentional?   It seems at odds with the comment block and also the switch man page states for the end of options marker:
    "This is not required when the matching patterns and bodies are grouped together in a single argument."
    
    Well it's not *required* as such - but it seems to me it is required if you want the best performance from a switch statement.
    
  5. is_private changed to: "0"
  6. login: "juliannoble2"
  7. priority changed to: "5 Medium"
  8. private_contact changed to: "957fdfcd8744611e3fe1f4896c7538b1d9bf47b2"
  9. resolution changed to: "None"
  10. severity changed to: "Minor"
  11. status changed to: "Open"
  12. submitter changed to: "juliannoble2"
  13. subsystem changed to: "18. Commands M-Z"
  14. title changed to:
    switch compilation difference with end of opts marker
    
  15. type changed to: "Bug"