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

"returns with nonliteral" expectations not working #295

Open
Gustrucco opened this issue Oct 23, 2020 · 2 comments
Open

"returns with nonliteral" expectations not working #295

Gustrucco opened this issue Oct 23, 2020 · 2 comments

Comments

@Gustrucco
Copy link
Contributor

I tried to use an expectation which case was exactly like this one:

expectation "`getAge` must not return a hardcoded value:
  %% equivalent to Intransitive:getAge Returns:WithNonliteral
  within `getAge` returns with nonliteral;
 

Here you can try it with this solution:

module Inodoro
  @cafeina_en_sangre = 90
  
  def self.compinche=(compinche)
    @compinche = compinche
  end
  
  def self.cafeina_en_sangre
    @cafeina_en_sangre  
  end
  
  def self.compinche
    @compinche
  end
end

module Eulogia
  @enojada = false
  
  def self.enojada?
    @enojada 
  end
end

module Mendieta
  @ganas_de_hablar = 5
  
  def self.ganas_de_hablar=(ganas_de_hablar)
    @ganas_de_hablar = ganas_de_hablar
  end
  
  def self.ganas_de_hablar
    @ganas_de_hablar
  end
end
@julian-berbel
Copy link
Member

julian-berbel commented Oct 27, 2020

So, the problem here is with ruby's implicit return. The following code:

module Inodoro
  def self.cafeina_en_sangre
    @cafeina_en_sangre  
  end
end

Produces this ast:

Object "Inodoro" (Method "cafeina_en_sangre" [] (Reference "@cafeina_en_sangre"))

Expectation returns with nonliteral searches for a Return expression where the returned value is not a literal, but since no Return expression is found anywhere, it fails. This same expectation works properly with an explicit return:

module Inodoro
  def self.cafeina_en_sangre
    return @cafeina_en_sangre  
  end
end

But it's not what one would normally do in ruby. We mulled over the idea of implicitly adding a Return expression to the last member of a sequence for ruby with @flbulgarelli, but this would likely cause a lot of other collateral failed expectations, such as returning the result of an assignment.

This isn't an easy solve, so we'll be leaving it for the future.

@julian-berbel julian-berbel removed their assignment Oct 27, 2020
@Gustrucco
Copy link
Contributor Author

Crystal clear. Thanks!

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