antlr-kotlin icon indicating copy to clipboard operation
antlr-kotlin copied to clipboard

Suppress or fix warnings in generated Kotlin code

Open hakanai opened this issue 1 year ago • 0 comments

There are a bunch of warnings in the code generated by the tool.

Notably:

The unused value here - an interesting case because if the setter isn't supported, maybe it should have generated a val instead of a var and merely not had a setter?

	    override var ruleIndex: Int
	        get() = Rules.RULE_start.id
	        set(value) { throw RuntimeException() }

The many cases of redundant casts - for these, the cast is always redundant because the is check will cause a smart cast:

		override fun enterRule(listener: ParseTreeListener) {
			if ( listener is RealExpressionListener ) (listener as RealExpressionListener).enterStart(this)
		}

And this one in the lexer where it's casting from Array<DFA> to Array<DFA?>:

		this.interpreter = LexerATNSimulator(this, ATN, decisionToDFA as Array<DFA?>, sharedContextCache)

If the warnings can be fixed, that'd be perfect, but it's generated code, so perhaps the generator could add @Suppress annotations to the classes to suppress any warnings they generate?

hakanai avatar Oct 18 '22 12:10 hakanai