flex-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Josh Tynjala (JIRA)" <j...@apache.org>
Subject [jira] [Created] (FLEX-35329) Initializing member variable/constant that is [Deprecated] incorrectly throws extra warning
Date Thu, 22 Jun 2017 17:19:00 GMT
Josh Tynjala created FLEX-35329:

             Summary: Initializing member variable/constant that is [Deprecated] incorrectly
throws extra warning
                 Key: FLEX-35329
                 URL: https://issues.apache.org/jira/browse/FLEX-35329
             Project: Apache Flex
          Issue Type: Bug
          Components: .Unspecified - Compiler
    Affects Versions: Apache Flex 4.16.0
            Reporter: Josh Tynjala
            Assignee: Josh Tynjala
            Priority: Minor

Consider the following class:

	import flash.display.Sprite;

	public class Deprecated extends Sprite
		public static var STATIC_DEPRECATED:String = "static";

		public static var STATIC_DEPRECATED2:String;

		public var memberDeprecated:String = "member";

		public var memberDeprecated2:String;

		public function Deprecated()
			STATIC_DEPRECATED = "new value";
			Deprecated.STATIC_DEPRECATED = "new value";
			memberDeprecated = "new value";
			this.memberDeprecated = "new value";
			STATIC_DEPRECATED2 = "new value";
			Deprecated.STATIC_DEPRECATED2 = "new value";
			memberDeprecated2 = "new value";
			this.memberDeprecated2 = "new value";

The compiler should give eight warnings for each of the lines in the constructor. However,
it actually gives 10 warnings. Here are the two extra warnings:

/Users/joshtynjala/Desktop/Deprecated/src/Deprecated.as(8): col: 21 Warning: 'STATIC_DEPRECATED'
has been deprecated.

		public static var STATIC_DEPRECATED:String = "static";

/Users/joshtynjala/Desktop/Deprecated/src/Deprecated.as(14): col: 14 Warning: 'memberDeprecated'
has been deprecated.

		public var memberDeprecated:String = "member";

Notice that there are no warnings for STATIC_DEPRECATED2 and memberDeprecated2 because they
are not initialized. It's only when a member or static variable is initialized that the warnings
are shown. It appears that when the compiler checks for usage of deprecated variables is a
little too aggressive.

The Falcon compiler and Adobe's ASC 2.0 compiler do not give these same extra warnings. They
only give a warning on actual usage.

These warnings make it difficult to deprecate a constant or another variable in an open source
library. It makes compile-time noisy with a lot of warnings that need to be ignored.

Note: When compiling with a library in SWC form, the compiler does not show these warnings.
I suspect that this is why this was never really encountered with the Flex framework, since
the SWCs are pre-compiled. However, for many open source libraries, developers often simply
use the source code with the -source-path compiler option instead of a pre-compiled SWC. That's
when these warnings can be seen. As a long-time library developer, I never used [Deprecated]
metadata because of this bug.

Solution, which I will implement:

In LintEvaluator, modify evaluate( Context cx, SetExpressionNode node ).

if (slot != null && !(node.expr instanceof QualifiedIdentifierNode))
	//if it's a qualified identifier node, then it's a member/static
	//variable on a class that is being initialized, like this:
	//public var memberVar:String = "hi";
	//this case should not have a warning!
	checkDeprecatedSlot(cx, node.expr, node.ref, slot);

The declaration of a member/static variable is a QualifiedIdentifierNode (qualified meaning
that it has modifiers like public/private, static, etc.), but actual usage will be an IdentifierNode
instead. So, if it's a QualifiedIdentifierNode, we know that we don't need to check if the
variable is deprecated or not.

This message was sent by Atlassian JIRA

View raw message