microsoft / microsoft/win32metadata
Add multiple AlsoUsableFor for autotype
- Dominant language
- C++
- Stars
- 1.5k
- Forks
- 149
- Avg merge
- 5d 16h
- Merged PRs (30d)
- 4
Description
In C++, we can have:
```cpp
class _jobject {};
class _jarray : public _jobject {};
class _jbooleanArray : public _jarray {};
typedef _jobject *jobject;
typedef _jarray *jarray;
typedef _jbooleanArray *jbooleanArray;
```
So that `jbooleanArray` can implicit convert to `jarray` and `jobject`. Now we can use `[AlsoUsableFor("jarray")]` to mark `jbooleanArray` can implicit convert to `jarray` or `[AlsoUsableFor("jobject")]` to mark `jbooleanArray` can implicit convert to `jobject`, but we cannot mark them both. If we mark the `[AlsoUsableFor("jarray")]` for `jbooleanArray` and `[AlsoUsableFor("jobject")]` for `jarray`, we need to implicit convert `jbooleanArray` to `jarray` and then implicit convert it to `jobject`. For example:
```cs
JValue* _args = stackalloc JValue[1];
JClass stringClass = env->functions->FindClass.CreateDelegate().Value(env, "java/lang/String"u8.AsPCSTR());
_args[0].l = (JArray)env->functions->NewObjectArray.CreateDelegate().Value(env, 0, stringClass, default);
env->functions->CallStaticVoidMethodA.CreateDelegate().Value(env, mainClass, entryPoint, _args);
```
So, it will be better if we can have `[AlsoUsableFor(["jarray", "jobject"])]` or can multiple mark `AlsoUsableFor` like `[AlsoUsableFor(["jarray"])][AlsoUsableFor("jobject")]` so that we can direct implicit convert `jbooleanArray` to `jobject`.
Contributor guide
Research direction
Start by locating the AlsoUsableFor attribute implementation and any tests covering implicit conversions. Compare supporting multiple target types with allowing repeated attributes, then add coverage showing that jbooleanArray can convert directly to both jarray and jobject; the issue is complete when the requested annotation form works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100