Way to track an instances in a compiler plugin?

Hi,

Is there a way to track a certain instance in a compiler plugin?
As in, if someone creates an instance and then, say, puts it inside an array, is there a way of knowing that the instance is in that array and at which index?

e.g. in code as follows:
val myCat = new Cat()
val cats = for(cat <- List(myCat)) yield cat

Does the compiler know that myCat is now in cats(0)? And is there a way to retreive that information in a compiler plugin?

Instances (of class, array etc.) do not exist at compile time.

@Aliceravier How do you want to rewrite this code?

val myCat = new Cat()
val cats = for(cat <- List(myCat)) yield cat

Fair. I just want to analyse it to check for errors. So I want to keep track of where instances are and what methods are called on them.

The usual term for this is “dataflow” or “dataflow analysis” — that might help you find references and resources.

3 Likes