Skip to content

Commit

Permalink
Fix return type restriction for ENV.fetch (#14919)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Aug 21, 2024
1 parent 4570027 commit f402215
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spec/std/env_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ describe "ENV" do
ENV.fetch("2")
end
end

it "fetches arbitrary default value" do
ENV.fetch("nonexistent", true).should be_true
end
end

it "handles unicode" do
Expand Down
2 changes: 1 addition & 1 deletion src/env.cr
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module ENV

# Retrieves a value corresponding to the given *key*. Return the second argument's value
# if the *key* does not exist.
def self.fetch(key, default) : String?
def self.fetch(key, default : T) : String | T forall T
fetch(key) { default }
end

Expand Down

0 comments on commit f402215

Please sign in to comment.