-
Notifications
You must be signed in to change notification settings - Fork 29
More new generic improvements #1131
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
Changes from 6 commits
7f2107d
899a2c3
e562964
a5a4f2f
40fa934
3534686
12ac80a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1976,6 +1976,14 @@ private void checkVarRef(NameRef e, boolean dynamicContext) { | |
| if (e.attrTyp() instanceof WurstTypeNamedScope) { | ||
| WurstTypeNamedScope wtns = (WurstTypeNamedScope) e.attrTyp(); | ||
| if (wtns.isStaticRef()) { | ||
| if (isUsedAsReceiverInExprMember(e) && isNewGenericTypeDef(def)) { | ||
| Element parent = e.getParent(); | ||
| parent.addError( | ||
| "Cannot access members via generic type '" + def.getName() + "' without specialization.\n" | ||
| + "New generics (<T:>) require a concrete specialization; use an instance receiver instead." | ||
|
Comment on lines
+1979
to
+1983
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new validation rejects all static member access on a new-generic type, because it only checks Useful? React with 👍 / 👎. |
||
| ); | ||
| return; | ||
| } | ||
| if (!isUsedAsReceiverInExprMember(e)) { | ||
| e.addError("Reference to " + e.getVarName() + " cannot be used as an expression."); | ||
| } else if (e.getParent() instanceof ExprMemberMethodDotDot) { | ||
|
|
@@ -2867,4 +2875,22 @@ private void checkParameter(WParameter param) { | |
| param.addError("Cannot use arrays as parameters."); | ||
| } | ||
| } | ||
|
|
||
| private static boolean isNewGenericTypeDef(@Nullable NameDef def) { | ||
| if (!(def instanceof AstElementWithTypeParameters)) { | ||
| return false; | ||
| } | ||
| AstElementWithTypeParameters g = (AstElementWithTypeParameters) def; | ||
| TypeParamDefs tps = g.getTypeParameters(); | ||
| if (tps == null || tps.size() == 0) { | ||
| return false; | ||
| } | ||
| // Treat "any new TP" as new-generic. Mixed is already diagnosed elsewhere. | ||
| for (TypeParamDef tp : tps) { | ||
| if (isTypeParamNewGeneric(tp)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.