melt-umn / silver

An attribute grammar-based programming language for composable language extensions
http://melt.cs.umn.edu/silver/
GNU Lesser General Public License v3.0
59 stars 7 forks source link

Implicit monads don't play nicely with convenience aspects #623

Open krame505 opened 2 years ago

krame505 commented 2 years ago

Example:

nonterminal Foos;
production consFoo top::Foos ::= Foos {}
production nilFoo top::Foos ::= {}

nonterminal Bars;
production consBar top::Bars ::= Integer Bars {}
production nilBar top::Bars ::= {}

implicit synthesized attribute genBars::RandomGen<Bars>;
attribute genBars occurs on Foos;
aspect genBars on top::Foos of
| consFoo(t) -> consBar(random, t.genBars)
| nilFoo() -> nilBar()
end;

This gives an error Attribute genBars has type silver:core:RandomGen<example:Bars> but the expression being assigned to it has type silver:core:RandomGen<silver:core:RandomGen<example:Bars:Bars>> on the start of the convenience aspect declaration.

It seems that some of degree of implicit monad rewriting is being applied, but it is not being done correctly.

krame505 commented 2 years ago

Note that while creating the above minimum example I was also able to cause an internal compiler error by changing consBar to consBars in the convenience aspect:

aspect genBars on top::Foos of
| consFoo(t) -> consBars(random, t.genBars)
| nilFoo() -> nilBar()
end;

Unsure if this is related to the above issue, but I was only able to reproduce this using convenience aspects in conjunction with implicit monads.