fzyzcjy/dart_interactive

Calling undefined getter on self defined class instance yields global variable

Quijx opened this issue · 2 comments

Quijx commented

Describe the bug
When calling a non existing getter with the same name as a global variable on another global variable that holds an instance of a self defined class, the value of the first global variable is returned, instead of throwing a NoSuchMethodError.

To Reproduce

  1. Enter the following lines in order:
>>> a=1
1
>>> class Foo {}
>>> f=Foo()
>>> f.a
1

Expected behavior
A NoSuchMethodError is thrown, just like if you were to define f='a string' instead of f=Foo() for example.

Actual Behavior
The value of the global variable a is returned even though an instance of the class Foo clearly does not have a getter called a.

Hi! Thanks for opening your first issue here! 😄

You are right, feel free to PR!

A good starting point is to look at the generated.dart file to see what is indeed generated