You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ensure that no empty prog.go file is created for txtar-formatted input
with leading whitespace characters, breaking compilation.
The internal process.start method creates temporary files based on the
user-supplied input. Although not explicitly documented, this input may
be txtar-formatted and thereby result in multiple files.
If a comment is detected in the txtar input, it will be written to the
separate prog.go file. This allows both txtar-formatted data and plain
Go source code to be handled.
Note that if there are leading whitespace characters in the input, they
will be interpreted as a comment and written into the prog.go file.
Because the file will then be missing "package main", the compilation
will fail.
I stumbled upon this error while attempting to create a working Go
module demo for present. Thus, creating a txtar input with go.{mod,sum}
and a source code file.
Turns out, when using present, the run message sent from the browser
prepends the body part with "\n\n" characters. When the input is not in
the txtar format, this does not matter since the Go compiler ignores the
empty lines. When, however, txtar is used, this results in an empty
prog.go file, breaking compilation.
This change ensures that the comment part after txtar parsing only
contains text before getting written into a Go source code file. I
decided to make this change within the Go code rather in present's front
end because it this affects all kind of usage involving whitespace
characters.
0 commit comments