I'm using smodel to designate semantic entities in my compiler, but I found a weird bug.
I'm testing for compiler bugs with one simple ActionScript 3 source that doesn't contain any sort of code (sdk/demo/builtins/src/library.as at master · whackengine/sdk · GitHub).
From factory:
pub fn create_type_constant(&self, referenced_type: &Entity) -> Result<Entity, DeferError> {
let r = TypeConstant::new(&self.0.arena, referenced_type, &self.0.class_type().defer()?);
// test bug
if r.static_type(self.0).is::<UnresolvedEntity>() {
println!("here");
}
Ok(r.into())
}
Prints here, here, here, here, here, ...
Note that static_type(host) retrieves the type of a value, variable slot or virtual slot.
Then here in Value
:
pub struct Value: Entity {
let ref m_static_type: Option<Entity> = None;
pub(crate) fn Value(static_type: &Entity) {
super();
self.set_m_static_type(Some(static_type.clone()));
if self.m_static_type().is_none() {
println!("Here");
}
}
pub override fn static_type(&self, host: &Database) -> Entity {
// i have tried here `self.m_static_type().is_none()`
// and it printed yes! Weird, right?
self.m_static_type().unwrap_or(host.unresolved_entity())
}
pub override fn set_static_type(&self, value: Entity) {
self.set_m_static_type(Some(value));
}
#[inheritdoc]
pub override fn property_static_type(&self, host: &Database) -> Entity {
self.static_type(host)
}
}
Does not print any sort of "here", "here", "here"...
Here's TypeConstant
:
pub struct TypeConstant: Constant {
let ref m_type: Option<Entity> = None;
pub(crate) fn TypeConstant(referenced_type: &Entity, static_type: &Entity) {
super(static_type);
self.set_m_type(Some(referenced_type.clone()));
}
pub override fn referenced_type(&self) -> Entity {
self.m_type().unwrap()
}
pub override fn clone_constant(&self, host: &Database) -> Entity {
host.factory().create_type_constant_with_static_type(&self.referenced_type(), &self.static_type(host))
}
}
Here's Constant
:
pub struct Constant: Value {
pub(crate) fn Constant(static_type: &Entity) {
super(static_type);
}
}
Here's the semantic model: sdk/crates/mxmlsemantics/src/semantics at master · whackengine/sdk · GitHub
How to play with it
At the Whack SDK workspace, run:
cargo run -- check --path demo --builtins demo/builtins
It'll check the sources at the demo
directory, using the demo/builtins
package as the built-in Whack library (which is a strip of the whacklib without code).
Source: View source