Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby Tree Deserialization Error #384

Closed
neanias opened this issue Dec 8, 2022 · 1 comment
Closed

Ruby Tree Deserialization Error #384

neanias opened this issue Dec 8, 2022 · 1 comment

Comments

@neanias
Copy link

neanias commented Dec 8, 2022

  • Ruby version: 3.1.3
  • Rubyfmt git sha: rubyfmt-main 0.8.0-pre ed99cc4 (output of rubyfmt --version, current Homebrew version) (if unsure, redownload the latest version and run against that)

Input file

# lib/day3.rb

# typed: true
# frozen_string_literal: true

require "sorbet-runtime"

class Day3
  extend T::Sig

  sig { params(item_file: String).void }
  def initialize(item_file)
    @rucksacks = T.let(File.readlines(item_file, chomp: true), T::Array[String])
  end

  sig { returns(Integer) }
  def part_one
    @rucksacks.sum do |rucksack|
      contents = rucksack.chars
      size = contents.length
      lhs = T.must(contents.take(size/2))
      rhs = T.must(contents.drop(size/2))
      T.must(lhs.intersection(rhs).map { calculate_priority(_1) }.first)
    end
  end

  sig { returns(Integer) }
  def part_two
    @rucksacks.each_slice(3).sum do |group|
      chars = group.map(&:chars)
      T.must(
        T.cast(
          (chars[0] & T.must(chars[1]) & T.must(chars[2])), T::Array[String]
        ).map { calculate_priority(_1) }.first
      )
    end
  end

  private

  sig { params(char: String).returns(Integer) }
  def calculate_priority(char)
    if char in ("a".."z")
      (char.ord % 97) + 1
    else
      (char.ord % 65) + 27
    end
  end
end

Rubyfmt's output

Error! source: lib/day3.rb

!!! Ruby Tree Deserialization Error !!!

Rubyfmt failed to correctly deserialize a tree from ripper. This is a bug that needs to be reported.
File a bug report at https://github.com/penelopezone/rubyfmt/issues/new.
Ideally you would include the full source code of the program you ran rubyfmt with.
If you can't do that for some reason, the best thing you can do is rerun rubyfmt on this program
with the debug binary with `2>log_file` on the end and then send us the log file that gets generated.

rubyfmt-debug output

This breaks because

I'm not sure what it should look like, sorry

@reese
Copy link
Collaborator

reese commented Dec 8, 2022

rubyfmt doesn't currently have support for pattern matching, but it's on the roadmap! Closing this out as a duplicate of #325, which is the original issue for supporting pattern matching.

@reese reese closed this as completed Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants