Skip to content

Commit 94444ee

Browse files
committed
perf: use nilable? to run Nil checking
1 parent fa96006 commit 94444ee

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/option.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ struct Some(T) < Option(T)
293293
@value : T
294294

295295
def initialize(value : T)
296-
{% if T.resolve.union_types.includes?(Nil) %}
296+
{% if T.nilable? %}
297297
raise WrapingNil.new("typeof #{{{Some}}} cannot includes Nil")
298298
{% end %}
299299

@@ -307,7 +307,7 @@ end
307307

308308
struct None(T) < Option(T)
309309
def initialize
310-
{% if T.resolve.union_types.includes?(Nil) %}
310+
{% if T.nilable? %}
311311
raise WrapingNil.new("typeof #{{{None}}} cannot includes Nil")
312312
{% end %}
313313
end

src/result.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ struct Ok(T, E) < Result(T, E)
292292
@value : T
293293

294294
def initialize(value : T)
295-
{% if T.resolve.union_types.includes?(Nil) || E.resolve.union_types.includes?(Nil) %}
295+
{% if T.nilable? || E.nilable? %}
296296
raise WrapingNil.new("typeof #{{{Ok}}} cannot includes Nil")
297297
{% end %}
298298

@@ -308,7 +308,7 @@ struct Err(T, E) < Result(T, E)
308308
@error : E
309309

310310
def initialize(error : E)
311-
{% if T.resolve.union_types.includes?(Nil) || E.resolve.union_types.includes?(Nil) %}
311+
{% if T.nilable? || E.nilable? %}
312312
raise WrapingNil.new("typeof #{{{Err}}} cannot includes Nil")
313313
{% end %}
314314

0 commit comments

Comments
 (0)