7

Bug introduced in V10 and partially fixed in V11.1.1


TLDR

Various of expressions which have fancy typeset form or are designed as UI elements won't survive ToExpression @* ToBoxes round-trip. And they should.

Examples

  • InterpolatingFunction (new)

    MakeExpression[#, StandardForm] & @ ToBoxes @ Interpolation[
        {{0, 0}, {1, 1}, {2, 3}, {3, 4}, {4, 3}, {5, 0}}
    ] // Shallow
    
    ErrorBox[ErrorBox[TagBox[<<5>>]]]
    

    ToExpression::esntx: Could not parse TagBox[<<1>>] as input.

  • InputField

    ToExpression @ ToBoxes @ InputField[Dynamic[x]]
    
     $Failed
    

    ToExpression::notstrbox: InputFieldBox[x] is not a string or a box. ToExpression can only interpret strings or boxes as Wolfram Language input.

    I don't expect InputField[Dynamic[x]] but at least something which is a proper expression, e.g. button works:

    ToExpression @ ToBoxes @ Button[Dynamic[x]] // InputForm
    
    Button[Dynamic[x], Evaluator -> None, Appearance -> Automatic, Method -> "Preemptive"]
    

    Things get weirder, MakeExpression can handle InputField case:

    InputForm @ MakeExpression[
        #,
        StandardForm
    ] & @ ToBoxes @ InputField[Dynamic[x]]
    
    HoldComplete[InputField[Dynamic[x]]]
    
  • FileNameSetter

    InputForm@MakeExpression[
      #,
      StandardForm
    ] & @ ToBoxes @ FileNameSetter[Dynamic[x]]
    
    ErrorBox[RowBox[{"FileNameSetterBoxes", "[", ErrorBox[Dynamic[x]], ",", "Open", ",", All, "]"}]]
    

    Syntax::sntxf: "FileNameSetterBoxes[" cannot be followed by "x,Open,All]".

Question

Are those bugs or have I missed something. Please help me understand that. :)


related

ToExpression and ToBoxes aren't inverses of each other?

How to make RawBoxes to be Expression

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • 1
    x = Dynamic[y]; MakeExpression@MakeBoxes@FileNameSetter[x] and x = Dynamic[y]; ToExpression@MakeBoxes@FileNameSetter[x] do work. – Karsten7 Sep 05 '16 at 12:44
  • 1
    I think this should be tagged [tag:bugs], because MakeExpression@MakeBoxes@FileNameSetter[Dynamic[f]] and ToExpression@ToBoxes@FileNameSetter[Dynamic[f]] works in Mathematica version 9.0.1. – Karsten7 Sep 05 '16 at 13:01
  • @Karsten7. thanks for checking! I agree but I wanted to ask community. – Kuba Sep 05 '16 at 13:03
  • In version 9 ToBoxes@FileNameSetter[Dynamic[f]] creates an InterpretationBox. Since version 10 a TemplateBox is created. – Karsten7 Sep 05 '16 at 13:22
  • For the FileNameSetter case the explanation could simply be that the proper definition for MakeExpression[ TemplateBox[{name_, type_, filter_}, "FileNameSetterBoxes"], StandardForm] is missing. Do FileNameSetterBoxes even exist? – Karsten7 Sep 05 '16 at 14:10
  • 3
    @Karsten7. The definition does exist. But it's in the stylesheet. I.e., CurrentValue[{StyleDefinitions, "FileNameSetterBoxes"}]. Which the FE understands, but the kernel does not. So this does properly roundtrip to output cells and back to input cells, but not through the more constrained MakeBoxes/MakeExpression roundtrip. – John Fultz Sep 07 '16 at 13:52

1 Answers1

0

A support case with the identification [CASE:3706792] was created.

  • InputField

    [...] This is an issue with ToExpression. I have brought it to the attention the relevant developers and they are further investigating the issue. [...]

    Bug introduced in V10 and persisting through V11.1.1

  • FileNameSetter

    [...] the issue for FileNameSetter is different than in the other cases [...]

    Bug introduced in V10 and fixed V11.1.1

Kuba
  • 136,707
  • 13
  • 279
  • 740