Skip to content

Commit

Permalink
Refactor some type restrictions in the compiler (#11531)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Dec 10, 2021
1 parent a73c05a commit a9ee750
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion spec/compiler/semantic/doc_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe "Semantic: doc" do
end
), wants_doc: true
program = result.program
ann = program.types["Flags"]
ann = program.types["Flags"].as(Crystal::AnnotationType)
foo = program.types["Foo"]
foo.annotation(ann).should_not be_nil
foo.doc.should eq("Hello")
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/annotatable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ module Crystal
end

# Returns the last defined annotation with the given type, if any, or `nil` otherwise
def annotation(annotation_type) : Annotation?
def annotation(annotation_type : AnnotationType) : Annotation?
@annotations.try &.[annotation_type]?.try &.last?
end

# Returns all annotations with the given type, if any, or `nil` otherwise
def annotations(annotation_type) : Array(Annotation)?
def annotations(annotation_type : AnnotationType) : Array(Annotation)?
@annotations.try &.[annotation_type]?
end
end
Expand Down
9 changes: 4 additions & 5 deletions src/compiler/crystal/semantic/type_declaration_processor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,8 @@ struct Crystal::TypeDeclarationProcessor

private def compute_non_nilable_instance_vars_multi(owner, infos)
# Get ancestor's non-nilable variables
ancestor = owner.ancestors.first?
ancestor = uninstantiate(ancestor)
if ancestor
if ancestor = owner.ancestors.first?
ancestor = uninstantiate(ancestor)
ancestor_non_nilable = @non_nilable_instance_vars[ancestor]?
end

Expand Down Expand Up @@ -758,9 +757,9 @@ struct Crystal::TypeDeclarationProcessor
end
end

private def uninstantiate(type)
private def uninstantiate(type) : Type
if type.is_a?(GenericInstanceType)
type.generic_type
type.generic_type.as(Type)
else
type
end
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/tools/playground/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ module Crystal::Playground

agent_ws = PathWebSocketHandler.new "/agent" do |ws, context|
match_data = context.request.path.not_nil!.match(/\/(\d+)\/(\d+)$/).not_nil!
session_key = match_data[1]?.try(&.to_i)
tag = match_data[2]?.try(&.to_i)
session_key = match_data[1].to_i
tag = match_data[2].to_i
Log.info { "#{context.request.path} WebSocket connected (session=#{session_key}, tag=#{tag})" }

session = @sessions[session_key]
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/tools/typed_def_processor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Crystal::TypedDefProcessor

private def process_result(result : Compiler::Result)
process_type result.program
if file_module = result.program.file_module? target_location.original_filename
if (filename = target_location.original_filename) && (file_module = result.program.file_module?(filename))
process_type file_module
end
end
Expand Down

0 comments on commit a9ee750

Please sign in to comment.