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

Make Meta.get_annotation work for constructor #6633

Merged
merged 1 commit into from
May 10, 2023
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.enso.interpreter.node.expression.builtin.meta;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.library.CachedLibrary;
import org.enso.interpreter.dsl.BuiltinMethod;
import org.enso.interpreter.node.BaseNode;
import org.enso.interpreter.node.callable.thunk.ThunkExecutorNode;
Expand All @@ -18,6 +13,12 @@
import org.enso.interpreter.runtime.scope.ModuleScope;
import org.enso.interpreter.runtime.state.State;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.library.CachedLibrary;

@BuiltinMethod(
type = "Meta",
name = "get_annotation",
Expand Down Expand Up @@ -51,15 +52,17 @@ Object doExecute(
return thunkExecutorNode.executeThunk(frame, thunk, state, getTailStatus());
}
}
AtomConstructor constructor = getAtomConstructor(targetType, methodName);
if (constructor != null) {
Function constructorFunction = constructor.getConstructorFunction();
String parameterName = expectStringNode.execute(parameter);
Annotation annotation = constructorFunction.getSchema().getAnnotation(parameterName);
if (annotation != null) {
Function thunk =
Function.thunk(annotation.getExpression().getCallTarget(), frame.materialize());
return thunkExecutorNode.executeThunk(frame, thunk, state, getTailStatus());
if (target instanceof Type type) {
AtomConstructor constructor = getAtomConstructor(type, methodName);
if (constructor != null) {
Function constructorFunction = constructor.getConstructorFunction();
String parameterName = expectStringNode.execute(parameter);
Annotation annotation = constructorFunction.getSchema().getAnnotation(parameterName);
if (annotation != null) {
Function thunk =
Function.thunk(annotation.getExpression().getCallTarget(), frame.materialize());
return thunkExecutorNode.executeThunk(frame, thunk, state, getTailStatus());
}
}
}
return EnsoContext.get(this).getNothing();
Expand Down
11 changes: 9 additions & 2 deletions test/Tests/src/Semantic/Meta_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,16 @@ spec =

Meta.get_annotation value "my_method" "self" . should_equal "self"

Meta.get_annotation value "Value" "foo" 7 8 . should_equal 15
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was introduced by @4e6 in #4049, but I don't think it is correct. At least according to #6612 people expect that the self value is going to be My_Type itself. Negating the test to expect Nothing and adding "get annotations on constructor" set of checks below.

Test.specify "no constructor annotations on value" <|
value = My_Type.Value 99 "bar" True
Meta.get_annotation value "Value" "foo" . should_equal Nothing
Meta.get_annotation value "Value" "bar" . should_equal Nothing
Meta.get_annotation value "Value" "baz" . should_equal (My_Type.Value 1 2 3)
Meta.get_annotation value "Value" "baz" . should_equal Nothing

Test.specify "get annotations on constructor" <|
Meta.get_annotation My_Type "Value" "foo" 7 8 . should_equal 15
Meta.get_annotation My_Type "Value" "bar" . should_equal Nothing
Meta.get_annotation My_Type "Value" "baz" . should_equal (My_Type.Value 1 2 3)

Test.group "Check Nothing and NaN" <|
Test.specify "Nothing.is_a Nothing" <|
Expand Down