Skip to content

[swift][cpd] Exception when running for Swift 4 code (KeyPath) #678

@nalexn

Description

@nalexn

cpd stopped working after I migrated the source code to Swift 4.

The problem: pmd cpd quits with an exception.

A full command showcasing the problem:
pmd cpd --language swift --minimum-tokens 50 --files source.swift

Result of running the command above:

net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file <path to file> at line 62, column 60.  Encountered: token recognition error at: '\.'
	at net.sourceforge.pmd.cpd.SwiftTokenizer.tokenize(SwiftTokenizer.java:48)
	at net.sourceforge.pmd.cpd.CPD.addAndThrowLexicalError(CPD.java:142)
	at net.sourceforge.pmd.cpd.CPD.add(CPD.java:137)
	at net.sourceforge.pmd.cpd.CPD.add(CPD.java:107)
	at net.sourceforge.pmd.cpd.CPD.add(CPD.java:69)
	at net.sourceforge.pmd.cpd.CPD.addDirectory(CPD.java:79)
	at net.sourceforge.pmd.cpd.CPD.addRecursively(CPD.java:64)
	at net.sourceforge.pmd.cpd.CPDCommandLineInterface.addSourcesFilesToCPD(CPDCommandLineInterface.java:125)
	at net.sourceforge.pmd.cpd.CPDCommandLineInterface.addSourceFilesToCPD(CPDCommandLineInterface.java:105)
	at net.sourceforge.pmd.cpd.CPDCommandLineInterface.main(CPDCommandLineInterface.java:83)
	at net.sourceforge.pmd.cpd.CPD.main(CPD.java:177)

The line of code for which cpd throws an exception is:

let observation = scrollView.observe(\.contentOffset, options: .new) { [weak self] (scrollView, _) in

Aparently cpd cannot handle the new Swift 4 syntax for KeyPath, which is \.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.in:cpdAffects the copy-paste detector

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions