Skip to content

||= Incorrect code removed to make an invalid block #95

@schneems

Description

@schneems

This code is totally valid:

  def ruby_install_binstub_path(ruby_layer_path = ".")
    @ruby_install_binstub_path ||=
      if ruby_version.build?
        "#{build_ruby_path}/bin"
      elsif ruby_version
        "#{ruby_layer_path}/#{slug_vendor_ruby}/bin"
      else
        ""
      end
  end

But if it exists alongside of another syntax error like:

            def ruby_install_binstub_path(ruby_layer_path = ".")
              @ruby_install_binstub_path ||=
                if ruby_version.build?
                  "#{build_ruby_path}/bin"
                elsif ruby_version
                  "#{ruby_layer_path}/#{slug_vendor_ruby}/bin"
                else
                  ""
                end
            end

            def add_node_js_binary
              return [] if node_js_preinstalled?

              if Pathname(build_path).join("package.json").exist? ||
                  bundler.has_gem?('execjs') ||
                  bundler.has_gem?('webpacker')
                [@node_installer.binary_path]
              else
                []
              end
            end

            def add_yarn_binary
              return [] if yarn_preinstalled?
          | # <== HERE
              if Pathname(build_path).join("yarn.lock").exist? || bundler.has_gem?('webpacker')
                [@yarn_installer.name]
              else
                []
              end
            end

Then dead end will remove the inside of the method first, making it:

def ruby_install_binstub_path(ruby_layer_path = ".")
  @ruby_install_binstub_path ||=

end

Which is not valid. Then when it re-parses that code it thinks that it has a syntax error, so it's never hidden.

One possible solution is to change the valid? check inside of CodeBlock to re-parse all the code lines instead of only what's visible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions