diff --git a/samples/sdl/fire.cr b/samples/sdl/fire.cr index 6af9ad7d5bd1..998b72443d8a 100644 --- a/samples/sdl/fire.cr +++ b/samples/sdl/fire.cr @@ -321,7 +321,7 @@ point_count = ARGV.size > 0 ? ARGV[0].to_i : 4 yellow = YellowColorPattern.new magenta = MagentaColorPattern.new cyan = CyanColorPattern.new -rainbow = RainbowColorPattern.new [yellow, magenta, cyan] of ColorPattern +rainbow = RainbowColorPattern.new [yellow, magenta, cyan] main_points = [] of MainPoint main_points << MainPoint.new(50, 50, -Math::PI / 8, 1.4, yellow) diff --git a/spec/compiler/codegen/class_spec.cr b/spec/compiler/codegen/class_spec.cr index abd4da3ba80e..5b7abf38a8ac 100644 --- a/spec/compiler/codegen/class_spec.cr +++ b/spec/compiler/codegen/class_spec.cr @@ -504,15 +504,7 @@ describe "Code gen: class" do it "does to_s for virtual metaclass type (3)" do run(%( - class Class - def name : String - {{ @type.name.stringify }} - end - - def to_s - name - end - end + require "prelude" class Foo; end class Bar < Foo; end diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index 2caba5fd3de6..5ebbf3aed14e 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -9,16 +9,7 @@ private def it_parses(string, expected_node, file = __FILE__, line = __LINE__) parser = Parser.new(string) parser.filename = "/foo/bar/baz.cr" node = parser.parse - - # If it's an Array, map it all to ASTNode (the array might be of a - # union that's not exactly ASTNode). Not having to write `[...] of ASTNode` - # simplifies testing a bit. - local_expected_node = expected_node - if local_expected_node.is_a?(Array) - local_expected_node = local_expected_node.map(&.as(ASTNode)) - end - - node.should eq(Expressions.from(local_expected_node)) + node.should eq(Expressions.from expected_node) end end @@ -992,7 +983,7 @@ module Crystal it_parses "def foo(x); end; x", [Def.new("foo", ["x".arg]), "x".call] it_parses "def foo; / /; end", Def.new("foo", body: regex(" ")) - it_parses "\"foo\#{bar}baz\"", StringInterpolation.new(["foo".string, "bar".call, "baz".string] of ASTNode) + it_parses "\"foo\#{bar}baz\"", StringInterpolation.new(["foo".string, "bar".call, "baz".string]) it_parses "qux \"foo\#{bar do end}baz\"", Call.new(nil, "qux", StringInterpolation.new(["foo".string, Call.new(nil, "bar", block: Block.new), "baz".string] of ASTNode)) it_parses "\"\#{1\n}\"", StringInterpolation.new([1.int32] of ASTNode) diff --git a/spec/compiler/semantic/class_spec.cr b/spec/compiler/semantic/class_spec.cr index 40eb162c72cc..897e119a64a6 100644 --- a/spec/compiler/semantic/class_spec.cr +++ b/spec/compiler/semantic/class_spec.cr @@ -178,7 +178,7 @@ describe "Semantic: class" do end a = Bar.new || Baz.new - ") { union_of types["Bar"], types["Baz"] } + ") { types["Foo"].virtual_type } end it "types class and subclass as one type" do diff --git a/spec/compiler/semantic/def_spec.cr b/spec/compiler/semantic/def_spec.cr index c5e6d4588dee..b689e530fb3a 100644 --- a/spec/compiler/semantic/def_spec.cr +++ b/spec/compiler/semantic/def_spec.cr @@ -316,7 +316,7 @@ describe "Semantic: def" do it "says compile-time type on error" do assert_error %( - class Foo + abstract class Foo end class Bar < Foo @@ -328,7 +328,7 @@ describe "Semantic: def" do class Baz < Foo end - f = Bar.new || Foo.new + f = Bar.new || Baz.new f.bar ), "compile-time type is Foo+" diff --git a/spec/compiler/semantic/struct_spec.cr b/spec/compiler/semantic/struct_spec.cr index af0af2ba59da..d6452cd474b0 100644 --- a/spec/compiler/semantic/struct_spec.cr +++ b/spec/compiler/semantic/struct_spec.cr @@ -39,7 +39,7 @@ describe "Semantic: struct" do struct Baz < Foo end - (Bar.new || Baz.new).as(Foo) + Bar.new || Baz.new ") { types["Foo"].virtual_type! } end diff --git a/spec/compiler/semantic/virtual_metaclass_spec.cr b/spec/compiler/semantic/virtual_metaclass_spec.cr index 41fc904ce58a..bb907f92b380 100644 --- a/spec/compiler/semantic/virtual_metaclass_spec.cr +++ b/spec/compiler/semantic/virtual_metaclass_spec.cr @@ -35,7 +35,7 @@ describe "Semantic: virtual metaclass" do it "allows allocating virtual type when base class is abstract" do assert_type(" - class Foo + abstract class Foo end class Bar < Foo @@ -44,7 +44,7 @@ describe "Semantic: virtual metaclass" do class Baz < Foo end - bar = Bar.new || Foo.new + bar = Bar.new || Baz.new baz = bar.class.allocate ") { types["Foo"].virtual_type } end diff --git a/spec/compiler/semantic/virtual_spec.cr b/spec/compiler/semantic/virtual_spec.cr index 29df3ccd2800..f98fa1536606 100644 --- a/spec/compiler/semantic/virtual_spec.cr +++ b/spec/compiler/semantic/virtual_spec.cr @@ -37,7 +37,7 @@ describe "Semantic: virtual" do end a = Bar.new || Baz.new - ") { union_of types["Bar"], types["Baz"] } + ") { types["Foo"].virtual_type } end it "types class and two subclasses" do diff --git a/src/compiler/crystal/codegen/cast.cr b/src/compiler/crystal/codegen/cast.cr index 955b2f74db88..ec276e3bf6b7 100644 --- a/src/compiler/crystal/codegen/cast.cr +++ b/src/compiler/crystal/codegen/cast.cr @@ -544,11 +544,6 @@ class Crystal::CodeGenVisitor end def upcast_distinct(value, to_type : MetaclassType | GenericClassInstanceMetaclassType | GenericModuleInstanceMetaclassType | VirtualMetaclassType, from_type) - # Special case: union of metaclasses is still represented as a union - if from_type.is_a?(MixedUnionType) - return load(union_type_id(value)) - end - value end diff --git a/src/compiler/crystal/semantic/literal_expander.cr b/src/compiler/crystal/semantic/literal_expander.cr index b1e7219e0de2..ed5404ec86a9 100644 --- a/src/compiler/crystal/semantic/literal_expander.cr +++ b/src/compiler/crystal/semantic/literal_expander.cr @@ -87,7 +87,7 @@ module Crystal exps = Array(ASTNode).new(node.entries.size + 2) exps << Assign.new(temp_var.clone, constructor).at(node) node.entries.each do |entry| - exps << Call.new(temp_var.clone, "[]=", [entry.key.clone, entry.value.clone] of ASTNode).at(node) + exps << Call.new(temp_var.clone, "[]=", [entry.key.clone, entry.value.clone]).at(node) end exps << temp_var.clone diff --git a/src/compiler/crystal/semantic/normalizer.cr b/src/compiler/crystal/semantic/normalizer.cr index fcd5428f52d4..a65e55986136 100644 --- a/src/compiler/crystal/semantic/normalizer.cr +++ b/src/compiler/crystal/semantic/normalizer.cr @@ -260,7 +260,7 @@ module Crystal # (1); (4) if assign - Expressions.new([assign, call] of ASTNode).at(node) + Expressions.new([assign, call]).at(node) else call end diff --git a/src/compiler/crystal/semantic/type_merge.cr b/src/compiler/crystal/semantic/type_merge.cr index dfc931da14ce..e86dfd4e5b21 100644 --- a/src/compiler/crystal/semantic/type_merge.cr +++ b/src/compiler/crystal/semantic/type_merge.cr @@ -120,19 +120,6 @@ module Crystal end def type_combine(types) - # Modules and types at a higher level in the hierarchy are the ones - # that will "delete" deeper types and combine them into virtual - # types (or just modules), so we put them in the front for the algorithm. - types.sort! do |t1, t2| - if t1.module? - -1 - elsif t2.module? - 1 - else - t1.depth <=> t2.depth - end - end - all_types = [types.shift] of Type types.each do |t2| @@ -346,10 +333,14 @@ private def class_common_ancestor(t1, t2) return t1 end - # If one type is deeper than the other, check if going up we find - # the one in the top, and if so we combine them. - # But if they are at the same depth we don't go up. - if t1.depth > t2.depth + if t1.depth == t2.depth + t1_superclass = t1.superclass + t2_superclass = t2.superclass + + if t1_superclass && t2_superclass + return t1_superclass.common_ancestor(t2_superclass) + end + elsif t1.depth > t2.depth t1_superclass = t1.superclass if t1_superclass return t1_superclass.common_ancestor(t2) diff --git a/src/compiler/crystal/tools/playground/agent_instrumentor_transformer.cr b/src/compiler/crystal/tools/playground/agent_instrumentor_transformer.cr index 7012dbbbf104..822608173f0d 100644 --- a/src/compiler/crystal/tools/playground/agent_instrumentor_transformer.cr +++ b/src/compiler/crystal/tools/playground/agent_instrumentor_transformer.cr @@ -96,11 +96,11 @@ module Crystal def transform(node : MultiAssign) node.values = if node.values.size == 1 - [instrument(node.values[0])] of ASTNode + [instrument(node.values[0])] else rhs = TupleLiteral.new(node.values) rhs.location = node.location - [instrument(rhs)] of ASTNode + [instrument(rhs)] end node end