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

Revert restrictict exp.@var to types in the same hierarchy #6484

Merged
merged 3 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions spec/compiler/codegen/c_struct_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,8 @@ describe "Code gen: struct" do
end
end

struct LibFoo::Foo
def _x
@x
end
end

f = LibFoo::Foo.new x: 123
f._x
f.@x
)).to_i.should eq(123)
end

Expand Down
12 changes: 2 additions & 10 deletions spec/compiler/codegen/class_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,10 @@ describe "Code gen: class" do
class Foo
def initialize(@x : Int32)
end

def self.read(foo)
foo.@x
end
end

foo = Foo.new(1)
Foo.read(foo)
foo.@x
)).to_i.should eq(1)
end

Expand All @@ -309,17 +305,13 @@ describe "Code gen: class" do
class Foo
def initialize(@x : Int32)
end

def self.read(foo)
foo.@x
end
end

class Bar < Foo
end

foo = Foo.new(1) || Bar.new(2)
Foo.read(foo)
foo.@x
)).to_i.should eq(1)
end

Expand Down
6 changes: 1 addition & 5 deletions spec/compiler/codegen/macro_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1459,13 +1459,9 @@ describe "Code gen: macro" do
{% begin %}
@x = 1
{% end %}

def _x
@x
end
end

Foo.new._x
Foo.new.@x
), inject_primitives: false).to_i.should eq(1)
end

Expand Down
6 changes: 1 addition & 5 deletions spec/compiler/codegen/pointer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,10 @@ describe "Code gen: pointer" do
def x
@x
end

def self.ptr(foo)
pointerof(foo.@x)
end
end

foo = Foo.new
Foo.ptr(foo).value = 123
pointerof(foo.@x).value = 123
foo.x
)).to_i.should eq(123)
end
Expand Down
6 changes: 1 addition & 5 deletions spec/compiler/codegen/proc_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,9 @@ describe "Code gen: proc" do
def self.foo
42
end

def _f
@f
end
end

Foo.new._f.call
Foo.new.@f.call
)).to_i.should eq(42)
end

Expand Down
6 changes: 1 addition & 5 deletions spec/compiler/codegen/struct_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,6 @@ describe "Code gen: struct" do
def initialize
@x = 21
end

def self.access(foo)
foo.@x
end
end

struct Bar < Foo
Expand All @@ -429,7 +425,7 @@ describe "Code gen: struct" do
struct Baz < Foo
end

Foo.access(Bar.new.as(Foo))
Bar.new.as(Foo).@x
)).to_i.should eq(42)
end

Expand Down
8 changes: 1 addition & 7 deletions spec/compiler/semantic/c_struct_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,8 @@ describe "Semantic: struct" do
end
end

struct LibFoo::Foo
def self.read(foo)
foo.@x
end
end

f = LibFoo::Foo.new x: 123
LibFoo::Foo.read(f)
f.@x
)) { int32 }
end

Expand Down
50 changes: 39 additions & 11 deletions spec/compiler/semantic/class_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,47 @@ describe "Semantic: class" do
assert_error "Number.allocate", "can't instantiate abstract struct Number"
end

it "errors if reading ivar from non-ivar container" do
assert_error %(
struct Int32
def foo
1.@y
it "reads an object instance var" do
assert_type(%(
class Foo
def initialize(@x : Int32)
end
end

foo = Foo.new(1)
foo.@x
)) { int32 }
end

it "reads a virtual type instance var" do
assert_type(%(
class Foo
def initialize(@x : Int32)
end
end

1.foo
class Bar < Foo
end

foo = Foo.new(1) || Bar.new(2)
foo.@x
)) { int32 }
end

it "errors if reading non-existent ivar" do
assert_error %(
class Foo
end

foo = Foo.new
foo.@y
),
"Can't infer the type of instance variable '@y' of Foo"
end

it "errors if reading ivar from non-ivar container" do
assert_error %(
1.@y
),
"can't use instance variables inside primitive types (at Int32)"
end
Expand Down Expand Up @@ -924,14 +956,10 @@ describe "Semantic: class" do
def foo
@foo
end

def self.read(foo)
foo.@foo
end
end

f = Foo.new
Foo.read(f)
f.@foo
),
"Can't infer the type of instance variable '@foo' of Foo"
end
Expand Down
34 changes: 5 additions & 29 deletions spec/compiler/semantic/instance_var_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -888,13 +888,9 @@ describe "Semantic: instance var" do
def x
@x ||= 1
end

def _x
@x
end
end

Foo.new._x
Foo.new.@x
)) { nilable int32 }
end

Expand All @@ -904,13 +900,9 @@ describe "Semantic: instance var" do
def x
x = @x ||= 1
end

def _x
@x
end
end

Foo.new._x
Foo.new.@x
)) { nilable int32 }
end

Expand Down Expand Up @@ -4705,13 +4697,9 @@ describe "Semantic: instance var" do
@never_nil = 2
end
end

def _never_nil
@never_nil
end
end

Foo.new._never_nil
Foo.new.@never_nil
)) { int32 }
end

Expand All @@ -4726,10 +4714,6 @@ describe "Semantic: instance var" do
@never_nil = 2
end
end

def _never_nil
@never_nil
end
end

class Bar
Expand All @@ -4740,13 +4724,9 @@ describe "Semantic: instance var" do
@never_nil = 2
end
end

def _never_nil
@never_nil
end
end

{Foo.new._never_nil, Bar.new._never_nil}
{Foo.new.@never_nil, Bar.new.@never_nil}
)) { tuple_of([int32, int32]) }
end

Expand Down Expand Up @@ -4860,13 +4840,9 @@ describe "Semantic: instance var" do

class Foo
@foo = Gen(Int32 | A).new

def _foo
@foo
end
end

Foo.new._foo
Foo.new.@foo
)) { generic_class "Gen", union_of(int32, types["A"]) }
end

Expand Down
Loading