From 8f4728007079175ab6ba38aae7fcae8a40e66a56 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Thu, 24 Nov 2011 08:46:00 +0200 Subject: [PATCH 01/17] making code window to show full stacktrace in case of error --- .../jet/plugin/internal/codewindow/BytecodeToolwindow.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java b/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java index 58d672f6d67..fbabf4cc567 100644 --- a/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java +++ b/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java @@ -27,6 +27,8 @@ import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import javax.swing.*; import java.awt.*; +import java.io.PrintWriter; +import java.io.StringWriter; public class BytecodeToolwindow extends JPanel { private static final int UPDATE_DELAY = 500; @@ -93,7 +95,9 @@ public class BytecodeToolwindow extends JPanel { AnalyzingUtils.checkForSyntacticErrors(file); state.compile(file); } catch (Exception e) { - return e.toString(); + StringWriter out = new StringWriter(1024); + e.printStackTrace(new PrintWriter(out)); + return out.toString(); } From 4c4742354af96d4a835ae4c978dd590c17cfe346 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 24 Nov 2011 14:34:16 +0400 Subject: [PATCH 02/17] Bytecode range highlighting according to selection in tracked editor (doesn't work well with closures yet) --- .../codewindow/BytecodeToolwindow.java | 67 +++++++++++++++++-- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java b/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java index fbabf4cc567..4d41020ad39 100644 --- a/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java +++ b/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java @@ -6,12 +6,14 @@ package org.jetbrains.jet.plugin.internal.codewindow; import com.intellij.ide.highlighter.JavaFileType; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowFactory; @@ -29,6 +31,7 @@ import javax.swing.*; import java.awt.*; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.Scanner; public class BytecodeToolwindow extends JPanel { private static final int UPDATE_DELAY = 500; @@ -36,7 +39,7 @@ public class BytecodeToolwindow extends JPanel { private final Alarm myUpdateAlarm; private Location myCurrentLocation; private final Project myProject; - + public BytecodeToolwindow(Project project) { super(new BorderLayout()); @@ -47,17 +50,17 @@ public class BytecodeToolwindow extends JPanel { myUpdateAlarm.addRequest(new Runnable() { @Override public void run() { + myUpdateAlarm.addRequest(this, UPDATE_DELAY); Location location = Location.fromEditor(FileEditorManager.getInstance(myProject).getSelectedTextEditor()); if (!Comparing.equal(location, myCurrentLocation)) { + updateBytecode(location, myCurrentLocation); myCurrentLocation = location; - updateBytecode(location); } - myUpdateAlarm.addRequest(this, UPDATE_DELAY); } }, UPDATE_DELAY); } - private void updateBytecode(Location location) { + private void updateBytecode(Location location, Location oldLocation) { Editor editor = location.editor; if (editor == null) { @@ -76,10 +79,64 @@ public class BytecodeToolwindow extends JPanel { return; } - setText(generateToText((JetFile) psiFile)); + if (oldLocation == null || !Comparing.equal(oldLocation.editor, location.editor) || oldLocation.modificationStamp != location.modificationStamp) { + setText(generateToText((JetFile) psiFile)); + } + + Document document = editor.getDocument(); + int startLine = document.getLineNumber(location.startOffset); + int endLine = document.getLineNumber(location.endOffset); + if (endLine > startLine && location.endOffset > 0 && document.getCharsSequence().charAt(location.endOffset - 1) == '\n') endLine--; + + Document byteCodeDocument = myEditor.getDocument(); + Pair linesRange = mapLines(byteCodeDocument.getText(), startLine, endLine); + + myEditor.getSelectionModel().setSelection(byteCodeDocument.getLineStartOffset(linesRange.first), + Math.min(byteCodeDocument.getLineStartOffset(linesRange.second + 1), byteCodeDocument.getTextLength())); } } + private static Pair mapLines(String text, int startLine, int endLine) { + int byteCodeLine = 0; + int byteCodeStartLine = -1; + int byteCodeEndLine = -1; + + for (String line : text.split("\n")) { + line = line.trim(); + + if (line.startsWith("LINENUMBER")) { + int ktLineNum = new Scanner(line.substring("LINENUMBER".length())).nextInt() - 1; + + if (byteCodeStartLine < 0 && ktLineNum >= startLine) { + byteCodeStartLine = byteCodeLine; + } + + if (byteCodeEndLine < 0 && ktLineNum > endLine) { + byteCodeEndLine = byteCodeLine - 1; + break; + } + } + + if (byteCodeStartLine >= 0 && (line.startsWith("MAXSTACK") || line.startsWith("LOCALVARIABLE") || line.isEmpty())) { + byteCodeEndLine = byteCodeLine - 1; + break; + } + + + byteCodeLine++; + } + + + + if (byteCodeStartLine == -1 || byteCodeEndLine == -1) { + return new Pair(0, 0); + } + else { + return new Pair(byteCodeStartLine, byteCodeEndLine); + } + + } + private void setText(final String text) { new WriteCommandAction(myProject) { @Override From 12a0b5a01b7ff49d192085edf0dda8798feea83a Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 24 Nov 2011 14:45:59 +0400 Subject: [PATCH 03/17] Better line mapping if multiple classes where generated for the file --- .../codewindow/BytecodeToolwindow.java | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java b/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java index 4d41020ad39..ad1f700d7fd 100644 --- a/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java +++ b/idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java @@ -9,6 +9,7 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; +import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.Project; @@ -31,6 +32,9 @@ import javax.swing.*; import java.awt.*; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Scanner; public class BytecodeToolwindow extends JPanel { @@ -91,8 +95,15 @@ public class BytecodeToolwindow extends JPanel { Document byteCodeDocument = myEditor.getDocument(); Pair linesRange = mapLines(byteCodeDocument.getText(), startLine, endLine); - myEditor.getSelectionModel().setSelection(byteCodeDocument.getLineStartOffset(linesRange.first), - Math.min(byteCodeDocument.getLineStartOffset(linesRange.second + 1), byteCodeDocument.getTextLength())); + int startOffset = byteCodeDocument.getLineStartOffset(linesRange.first); + int endOffset = Math.min(byteCodeDocument.getLineStartOffset(linesRange.second + 1), byteCodeDocument.getTextLength()); + myEditor.getCaretModel().moveToOffset(endOffset); + myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); + myEditor.getCaretModel().moveToOffset(startOffset); + myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); + + myEditor.getSelectionModel().setSelection(startOffset, + endOffset); } } @@ -101,17 +112,35 @@ public class BytecodeToolwindow extends JPanel { int byteCodeStartLine = -1; int byteCodeEndLine = -1; + List lines = new ArrayList(); + for (String line : text.split("\n")) { + line = line.trim(); + + if (line.startsWith("LINENUMBER")) { + int ktLineNum = new Scanner(line.substring("LINENUMBER".length())).nextInt() - 1; + lines.add(ktLineNum); + } + } + Collections.sort(lines); + + for (Integer line : lines) { + if (line >= startLine) { + startLine = line; + break; + } + } + for (String line : text.split("\n")) { line = line.trim(); if (line.startsWith("LINENUMBER")) { int ktLineNum = new Scanner(line.substring("LINENUMBER".length())).nextInt() - 1; - if (byteCodeStartLine < 0 && ktLineNum >= startLine) { + if (byteCodeStartLine < 0 && ktLineNum == startLine) { byteCodeStartLine = byteCodeLine; } - if (byteCodeEndLine < 0 && ktLineNum > endLine) { + if (byteCodeStartLine > 0&& ktLineNum > endLine) { byteCodeEndLine = byteCodeLine - 1; break; } From dca64c8ba98d9c871408c93a599ddda3a07b883e Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Thu, 24 Nov 2011 15:18:37 +0400 Subject: [PATCH 04/17] Revert "+-JDK and -NOSTDLIB options" This reverts commit 8222011874d6177e1e24f0750518271d6213758c. +- JDK will be restored in next commit removal of -STDLIB was requested by Andrey Breslav --- .../jet/codegen/GenerationState.java | 4 +- .../jet/compiler/CompileSession.java | 2 +- .../jet/lang/resolve/java/AnalyzerFacade.java | 2 +- .../jet/lang/JetSemanticServices.java | 6 +-- .../jet/lang/resolve/AnalyzingUtils.java | 10 ++-- .../jet/lang/types/JetStandardLibrary.java | 50 +++++-------------- .../checkerWithErrorTypes/full/Casts.jet | 4 +- .../jet/checkers/CheckerTestUtilTest.java | 2 +- .../jet/checkers/FullJetPsiCheckerTest.java | 11 +--- .../jet/checkers/QuickJetPsiCheckerTest.java | 8 +-- .../jetbrains/jet/resolve/JetResolveTest.java | 2 +- .../jet/plugin/compiler/JetCompiler.java | 2 +- .../jet/plugin/java/JavaElementFinder.java | 2 +- 13 files changed, 28 insertions(+), 77 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java index c106eeaed70..56b432cf2c9 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java @@ -30,7 +30,7 @@ public class GenerationState { public GenerationState(Project project, ClassBuilderFactory builderFactory) { this.project = project; - this.standardLibrary = JetStandardLibrary.getJetStandardLibrary(project, true); + this.standardLibrary = JetStandardLibrary.getJetStandardLibrary(project); this.factory = new ClassFileFactory(builderFactory, this); this.intrinsics = new IntrinsicMethods(project, standardLibrary); } @@ -82,7 +82,7 @@ public class GenerationState { public void compile(JetFile psiFile) { final JetNamespace namespace = psiFile.getRootNamespace(); - final BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true).analyzeNamespace(namespace, JetControlFlowDataTraceFactory.EMPTY); + final BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).analyzeNamespace(namespace, JetControlFlowDataTraceFactory.EMPTY); AnalyzingUtils.throwExceptionOnErrors(bindingContext); compileCorrectNamespaces(bindingContext, Collections.singletonList(namespace)); // NamespaceCodegen codegen = forNamespace(namespace); diff --git a/compiler/backend/src/org/jetbrains/jet/compiler/CompileSession.java b/compiler/backend/src/org/jetbrains/jet/compiler/CompileSession.java index 43f4661b726..e90fda9eb8a 100644 --- a/compiler/backend/src/org/jetbrains/jet/compiler/CompileSession.java +++ b/compiler/backend/src/org/jetbrains/jet/compiler/CompileSession.java @@ -84,7 +84,7 @@ public class CompileSession { } return false; } - final AnalyzingUtils instance = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true); + final AnalyzingUtils instance = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS); List allNamespaces = new ArrayList(mySourceFileNamespaces); allNamespaces.addAll(myLibrarySourceFileNamespaces); myBindingContext = instance.analyzeNamespaces(myEnvironment.getProject(), allNamespaces, Predicates.alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java index 9be40fce997..6ad38396927 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java @@ -34,7 +34,7 @@ public class AnalyzerFacade { } }; - private static final AnalyzingUtils ANALYZING_UTILS = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true); + private static final AnalyzingUtils ANALYZING_UTILS = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS); private final static Key> BINDING_CONTEXT = Key.create("BINDING_CONTEXT"); private static final Object lock = new Object(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/JetSemanticServices.java b/compiler/frontend/src/org/jetbrains/jet/lang/JetSemanticServices.java index 9a92d86c8d0..36fadfc8f60 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/JetSemanticServices.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/JetSemanticServices.java @@ -17,11 +17,7 @@ public class JetSemanticServices { } public static JetSemanticServices createSemanticServices(Project project) { - return createSemanticServices(project, true); - } - - public static JetSemanticServices createSemanticServices(Project project, boolean loadFullLibrary) { - return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project, loadFullLibrary)); + return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project)); } private final JetStandardLibrary standardLibrary; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java index 2eb18914627..483a5673739 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java @@ -28,8 +28,8 @@ import java.util.*; * @author abreslav */ public class AnalyzingUtils { - public static AnalyzingUtils getInstance(@NotNull ImportingStrategy importingStrategy, boolean loadStdlib) { - return new AnalyzingUtils(importingStrategy, loadStdlib); + public static AnalyzingUtils getInstance(@NotNull ImportingStrategy importingStrategy) { + return new AnalyzingUtils(importingStrategy); } public static void checkForSyntacticErrors(@NotNull PsiElement root) { @@ -53,11 +53,9 @@ public class AnalyzingUtils { } private final ImportingStrategy importingStrategy; - private final boolean loadStdlib; - private AnalyzingUtils(ImportingStrategy importingStrategy, boolean loadStdlib) { + private AnalyzingUtils(ImportingStrategy importingStrategy) { this.importingStrategy = importingStrategy; - this.loadStdlib = loadStdlib; } public BindingContext analyzeNamespace(@NotNull JetNamespace namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) { @@ -73,7 +71,7 @@ public class AnalyzingUtils { @NotNull Predicate filesToAnalyzeCompletely, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) { BindingTraceContext bindingTraceContext = new BindingTraceContext(); - JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project, loadStdlib); + JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project); JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope(); ModuleDescriptor owner = new ModuleDescriptor(""); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java index c90e935e043..62923713125 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java @@ -29,24 +29,16 @@ import java.util.Set; public class JetStandardLibrary { // TODO : consider releasing this memory - private static JetStandardLibrary cachedFullLibrary = null; - private static JetStandardLibrary cachedQuickLibrary = null; + private static JetStandardLibrary cachedLibrary = null; // private static final Map standardLibraryCache = new HashMap(); // TODO : double checked locking synchronized - public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project, boolean loadFullLibrary) { - if (loadFullLibrary) { - if (cachedFullLibrary == null) { - cachedFullLibrary = new JetStandardLibrary(project, true); - } - return cachedFullLibrary; - } else { - if (cachedQuickLibrary == null) { - cachedQuickLibrary = new JetStandardLibrary(project, false); - } - return cachedQuickLibrary; + public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project) { + if (cachedLibrary == null) { + cachedLibrary = new JetStandardLibrary(project); } + return cachedLibrary; // JetStandardLibrary standardLibrary = standardLibraryCache.get(project); // if (standardLibrary == null) { // standardLibrary = new JetStandardLibrary(project); @@ -55,12 +47,6 @@ public class JetStandardLibrary { // return standardLibrary; } - public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project) { - return getJetStandardLibrary(project, true); - } - - private final boolean loadFullLibrary; - private JetScope libraryScope; private ClassDescriptor numberClass; @@ -136,27 +122,20 @@ public class JetStandardLibrary { private NamespaceDescriptor typeInfoNamespace; private Set typeInfoFunction; - private JetStandardLibrary(@NotNull Project project, boolean loadFullLibrary) { - this.loadFullLibrary = loadFullLibrary; - + private JetStandardLibrary(@NotNull Project project) { + // TODO : review + InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/Library.jet"); try { - JetFile file = null; - if (loadFullLibrary) { - // TODO : review - InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/Library.jet"); - //noinspection IOResourceOpenedButNotSafelyClosed - file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet", - JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream))); - } + //noinspection IOResourceOpenedButNotSafelyClosed + JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet", + JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream))); JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this); BindingTraceContext bindingTraceContext = new BindingTraceContext(); WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope"); // this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations()); // bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations()); - if (loadFullLibrary) { - TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace()); - } + TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace()); // this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope(); AnalyzingUtils.throwExceptionOnErrors(bindingTraceContext.getBindingContext()); @@ -174,11 +153,6 @@ public class JetStandardLibrary { private void initStdClasses() { if(libraryScope == null) { this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope(); - - if (!loadFullLibrary) { - return; - } - this.numberClass = (ClassDescriptor) libraryScope.getClassifier("Number"); this.byteClass = (ClassDescriptor) libraryScope.getClassifier("Byte"); this.charClass = (ClassDescriptor) libraryScope.getClassifier("Char"); diff --git a/compiler/testData/checkerWithErrorTypes/full/Casts.jet b/compiler/testData/checkerWithErrorTypes/full/Casts.jet index e34a90b945a..163619fd4d0 100644 --- a/compiler/testData/checkerWithErrorTypes/full/Casts.jet +++ b/compiler/testData/checkerWithErrorTypes/full/Casts.jet @@ -1,5 +1,3 @@ -// -JDK - fun test() : Unit { var x : Int? = 0 var y : Int = 0 @@ -15,4 +13,4 @@ fun test() : Unit { x as? Int? : Int? y as? Int? : Int? () -} +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java b/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java index 8663cc4d9fc..06ffed74d04 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java @@ -81,7 +81,7 @@ public class CheckerTestUtilTest extends JetLiteFixture { } public void test(PsiFile psiFile) { - BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(ImportingStrategy.NONE, true), (JetFile) psiFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); + BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(ImportingStrategy.NONE), (JetFile) psiFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); String expectedText = CheckerTestUtil.addDiagnosticMarkersToText(psiFile, bindingContext).toString(); List diagnosedRanges = Lists.newArrayList(); diff --git a/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java b/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java index 5b4646d207e..986f6501d10 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java @@ -8,11 +8,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; -import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.ImportingStrategy; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade; -import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports; import java.util.List; @@ -45,13 +42,7 @@ public class FullJetPsiCheckerTest extends JetLiteFixture { String clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges); myFile = createPsiFile(myName, clearText); - - boolean loadStdlib = !expectedText.contains("-STDLIB"); - boolean importJdk = !expectedText.contains("-JDK"); - - ImportingStrategy importingStrategy = importJdk ? JavaDefaultImports.JAVA_DEFAULT_IMPORTS : ImportingStrategy.NONE; - - BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy, loadStdlib), myFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); + BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(myFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() { @Override diff --git a/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java b/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java index a69f04a21c7..d6ead64cdf1 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java @@ -13,7 +13,6 @@ import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.ImportingStrategy; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade; -import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports; import java.util.List; @@ -41,12 +40,7 @@ public class QuickJetPsiCheckerTest extends JetLiteFixture { createAndCheckPsiFile(name, clearText); JetFile jetFile = (JetFile) myFile; - boolean loadStdlib = !expectedText.contains("-STDLIB"); - boolean importJdk = expectedText.contains("+JDK"); - - ImportingStrategy importingStrategy = importJdk ? JavaDefaultImports.JAVA_DEFAULT_IMPORTS : ImportingStrategy.NONE; - - BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy, loadStdlib), jetFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); + BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(ImportingStrategy.NONE), jetFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() { @Override diff --git a/compiler/tests/org/jetbrains/jet/resolve/JetResolveTest.java b/compiler/tests/org/jetbrains/jet/resolve/JetResolveTest.java index f4bf68958a1..ca206ae88c0 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/JetResolveTest.java +++ b/compiler/tests/org/jetbrains/jet/resolve/JetResolveTest.java @@ -44,7 +44,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase { @Override protected ExpectedResolveData getExpectedResolveData() { Project project = getProject(); - JetStandardLibrary lib = JetStandardLibrary.getJetStandardLibrary(project, true); + JetStandardLibrary lib = JetStandardLibrary.getJetStandardLibrary(project); Map nameToDescriptor = new HashMap(); nameToDescriptor.put("std::Int.plus(Int)", standardFunction(lib.getInt(), "plus", lib.getIntType())); FunctionDescriptor descriptorForGet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "get", lib.getIntType()); diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java b/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java index 0a34294d80f..0a16cb56f58 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java @@ -80,7 +80,7 @@ public class JetCompiler implements TranslatingCompiler { } } - BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true).analyzeNamespaces( + BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).analyzeNamespaces( compileContext.getProject(), namespaces, Predicates.alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY); diff --git a/idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java b/idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java index 1967f70b22e..7cfa0fe1b86 100644 --- a/idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java +++ b/idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java @@ -211,7 +211,7 @@ public class JavaElementFinder extends PsiElementFinder { if (dirty.size() > 0) { - final BindingContext context = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true).shallowAnalyzeFiles(dirty); + final BindingContext context = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).shallowAnalyzeFiles(dirty); state.compileCorrectNamespaces(context, AnalyzingUtils.collectRootNamespaces(dirty)); state.getFactory().files(); } From 648540ad0c7a8492a25008ceec2e90319cf89f7c Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Thu, 24 Nov 2011 15:18:41 +0400 Subject: [PATCH 05/17] restore +-JDK options --- .../jetbrains/jet/checkers/FullJetPsiCheckerTest.java | 9 ++++++++- .../jetbrains/jet/checkers/QuickJetPsiCheckerTest.java | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java b/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java index 986f6501d10..b16946132bf 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java @@ -8,8 +8,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; +import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.ImportingStrategy; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade; +import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports; import java.util.List; @@ -42,7 +45,11 @@ public class FullJetPsiCheckerTest extends JetLiteFixture { String clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges); myFile = createPsiFile(myName, clearText); - BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(myFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); + + boolean importJdk = !expectedText.contains("-JDK"); + ImportingStrategy importingStrategy = importJdk ? JavaDefaultImports.JAVA_DEFAULT_IMPORTS : ImportingStrategy.NONE; + + BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy), myFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() { @Override diff --git a/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java b/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java index d6ead64cdf1..d7ae428139f 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java @@ -13,6 +13,7 @@ import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.ImportingStrategy; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade; +import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports; import java.util.List; @@ -40,7 +41,11 @@ public class QuickJetPsiCheckerTest extends JetLiteFixture { createAndCheckPsiFile(name, clearText); JetFile jetFile = (JetFile) myFile; - BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(ImportingStrategy.NONE), jetFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); + + boolean importJdk = expectedText.contains("+JDK"); + ImportingStrategy importingStrategy = importJdk ? JavaDefaultImports.JAVA_DEFAULT_IMPORTS : ImportingStrategy.NONE; + + BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy), jetFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() { @Override From a79202b7e75b23e03211de7b0bf9c8309cd3577d Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Thu, 24 Nov 2011 15:24:10 +0400 Subject: [PATCH 06/17] Temporarily revert "more check for casts" (because commit broke seveal tests) This reverts commit 5d2dfcd48f5bf89ba8d5cb436914169a65b1628e. --- .../jet/lang/diagnostics/Errors.java | 6 +-- .../BasicExpressionTypingVisitor.java | 50 ------------------- .../PatternMatchingTypingVisitor.java | 32 +----------- .../full/cast/AsErasedError.jet | 4 -- .../full/cast/AsErasedFine.jet | 4 -- .../full/cast/AsErasedStar.jet | 4 -- .../full/cast/AsErasedWarning.jet | 3 -- .../full/cast/IsErasedAllow.jet | 5 -- .../cast/IsErasedAllowParameterSubtype.jet | 9 ---- .../full/cast/IsErasedDisallowFromAny.jet | 3 -- .../cast/IsErasedDisallowFromParameter.jet | 5 -- .../full/cast/IsErasedStar.jet | 3 -- .../full/cast/IsReified.jet | 3 -- .../full/cast/IsReifiedDisallow.jet | 3 -- .../full/cast/IsTraits.jet | 4 -- .../full/cast/WhenErasedDisallowFromAny.jet | 6 --- .../testData/codegen/patternMatching/is.jet | 4 +- 17 files changed, 5 insertions(+), 143 deletions(-) delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/AsErasedError.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/AsErasedFine.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/AsErasedStar.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/AsErasedWarning.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllow.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllowParameterSubtype.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromAny.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromParameter.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/IsErasedStar.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/IsReified.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/IsReifiedDisallow.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/IsTraits.jet delete mode 100644 compiler/testData/checkerWithErrorTypes/full/cast/WhenErasedDisallowFromAny.jet diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 785e9abbae6..da7edd9d6fe 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -16,7 +16,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Collection; import java.util.Iterator; -import java.util.List; import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR; import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING; @@ -276,10 +275,7 @@ public interface Errors { ParameterizedDiagnosticFactory2 TYPE_MISMATCH_IN_TUPLE_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "Type mismatch: subject is of type {0} but the pattern is of type Tuple{1}"); // TODO: message ParameterizedDiagnosticFactory2 TYPE_MISMATCH_IN_BINDING_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "{0} must be a supertype of {1}. Use 'is' to match against {0}"); ParameterizedDiagnosticFactory2 INCOMPATIBLE_TYPES = ParameterizedDiagnosticFactory2.create(ERROR, "Incompatible types: {0} and {1}"); - - ParameterizedDiagnosticFactory1 CANNOT_CHECK_FOR_ERASED = ParameterizedDiagnosticFactory1.create(ERROR, "Cannot check for instance of erased type: {0}"); - ParameterizedDiagnosticFactory2 UNCHECKED_CAST = ParameterizedDiagnosticFactory2.create(WARNING, "Unchecked cast: {0} to {1}"); - + ParameterizedDiagnosticFactory3> INCONSISTENT_TYPE_PARAMETER_VALUES = new ParameterizedDiagnosticFactory3>(ERROR, "Type parameter {0} of {1} has inconsistent values: {2}") { @Override protected String makeMessageForA(@NotNull TypeParameterDescriptor typeParameterDescriptor) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 10c3ca8cae5..0446105d479 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -1,7 +1,6 @@ package org.jetbrains.jet.lang.types.expressions; import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; @@ -9,7 +8,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetNodeTypes; import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.calls.CallMaker; @@ -247,58 +245,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { else { if (typeChecker.isSubtypeOf(actualType, targetType)) { context.trace.report(USELESS_CAST.on(expression, expression.getOperationSign())); - } else { - if (isCastErased(actualType, targetType)) { - context.trace.report(Errors.UNCHECKED_CAST.on(expression, actualType, targetType)); - } } } } - /** - * Check if assignment from ActualType to TargetType is erased. - * It is an error in "is" statement and warning in "as". - */ - public static boolean isCastErased(JetType actualType, JetType targetType) { - - JetType targetTypeClerared = TypeUtils.makeUnsubstitutedType( - (ClassDescriptor) targetType.getConstructor().getDeclarationDescriptor(), null); - - Multimap clearTypeSubstitutionMap = - TypeUtils.buildDeepSubstitutionMultimap(targetTypeClerared); - - Set clearSubstituted = new HashSet(); - - for (int i = 0; i < actualType.getConstructor().getParameters().size(); ++i) { - TypeParameterDescriptor subjectTypeParameterDescriptor = actualType.getConstructor().getParameters().get(i); - - Collection subst = clearTypeSubstitutionMap.get(subjectTypeParameterDescriptor.getTypeConstructor()); - for (TypeProjection proj : subst) { - clearSubstituted.add(proj.getType()); - } - } - - for (int i = 0; i < targetType.getConstructor().getParameters().size(); ++i) { - TypeParameterDescriptor typeParameter = targetType.getConstructor().getParameters().get(i); - TypeProjection typeProjection = targetType.getArguments().get(i); - - if (typeParameter.isReified()) { - continue; - } - - // "is List<*>" - if (typeProjection.equals(TypeUtils.makeStarProjection(typeParameter))) { - continue; - } - - // if parameter is mapped to nothing then it is erased - if (!clearSubstituted.contains(typeParameter.getDefaultType())) { - return true; - } - } - return false; - } - @Override public JetType visitTupleExpression(JetTupleExpression expression, ExpressionTypingContext context) { List entries = expression.getEntries(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java index 9a7c4d968c3..943343f4d70 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java @@ -1,14 +1,11 @@ package org.jetbrains.jet.lang.types.expressions; -import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import com.intellij.lang.ASTNode; import com.intellij.openapi.util.Ref; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; -import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue; @@ -20,7 +17,8 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver; import org.jetbrains.jet.lang.types.*; -import java.util.*; +import java.util.List; +import java.util.Set; import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.ensureBooleanResultWithCustomSubject; @@ -247,9 +245,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { } } - /* - * (a: SubjectType) is Type - */ private void checkTypeCompatibility(@Nullable JetType type, @NotNull JetType subjectType, @NotNull JetElement reportErrorOn) { // TODO : Take auto casts into account? if (type == null) { @@ -258,29 +253,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { if (TypeUtils.intersect(context.semanticServices.getTypeChecker(), Sets.newHashSet(type, subjectType)) == null) { // context.trace.getErrorHandler().genericError(reportErrorOn.getNode(), "Incompatible types: " + type + " and " + subjectType); context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType)); - return; - } - - { - // check parameters compatible - Multimap typeSubstritutionMap = TypeUtils.buildDeepSubstitutionMultimap(type); - - for (int i = 0; i < subjectType.getConstructor().getParameters().size(); ++i) { - TypeParameterDescriptor subjectTypeParameterDescriptor = subjectType.getConstructor().getParameters().get(i); - TypeProjection subjectParameterType = subjectType.getArguments().get(i); - - Collection xxy = typeSubstritutionMap.get(subjectTypeParameterDescriptor.getTypeConstructor()); - for (TypeProjection proj : xxy) { - if (!context.semanticServices.getTypeChecker().isSubtypeOf(subjectParameterType.getType(), proj.getType())) { - context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType)); - continue; - } - } - } - } - - if (BasicExpressionTypingVisitor.isCastErased(subjectType, type)) { - context.trace.report(Errors.CANNOT_CHECK_FOR_ERASED.on(reportErrorOn, type)); } } diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedError.jet b/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedError.jet deleted file mode 100644 index bff067d20ee..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedError.jet +++ /dev/null @@ -1,4 +0,0 @@ -import java.util.List; -import java.util.Collection; - -fun ff(c: Collection) = c as List diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedFine.jet b/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedFine.jet deleted file mode 100644 index 341f370d108..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedFine.jet +++ /dev/null @@ -1,4 +0,0 @@ -import java.util.List; -import java.util.Collection; - -fun ff(c: Collection) = c as List diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedStar.jet b/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedStar.jet deleted file mode 100644 index b9c2faf0d9a..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedStar.jet +++ /dev/null @@ -1,4 +0,0 @@ -import java.util.List; - -fun ff(l: Any) = l as List<*> - diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedWarning.jet b/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedWarning.jet deleted file mode 100644 index a55f6b7d58b..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedWarning.jet +++ /dev/null @@ -1,3 +0,0 @@ -import java.util.List; - -fun ff(a: Any) = a as List diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllow.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllow.jet deleted file mode 100644 index 7f32b79eba2..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllow.jet +++ /dev/null @@ -1,5 +0,0 @@ -import java.util.Collection; -import java.util.List; - -fun ff(l: Collection) = l is List - diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllowParameterSubtype.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllowParameterSubtype.jet deleted file mode 100644 index d1694229dc6..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllowParameterSubtype.jet +++ /dev/null @@ -1,9 +0,0 @@ -import java.util.Collection; -import java.util.List; - -open class A - -class B : A - -fun ff(l: Collection) = l is List - diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromAny.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromAny.jet deleted file mode 100644 index eb3b402ccc7..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromAny.jet +++ /dev/null @@ -1,3 +0,0 @@ -import java.util.List; - -fun ff(l: Any) = l is List diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromParameter.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromParameter.jet deleted file mode 100644 index a70b5932999..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromParameter.jet +++ /dev/null @@ -1,5 +0,0 @@ -import java.util.List; -import java.util.Collection; - -fun ff(l: Collection) = l is List - diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedStar.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedStar.jet deleted file mode 100644 index 404d8f8f3b0..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedStar.jet +++ /dev/null @@ -1,3 +0,0 @@ -import java.util.List; - -fun ff(l: Any) = l is List<*> diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsReified.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsReified.jet deleted file mode 100644 index 247196d6e84..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsReified.jet +++ /dev/null @@ -1,3 +0,0 @@ -class MyList - -fun ff(a: Any) = a is MyList diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsReifiedDisallow.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsReifiedDisallow.jet deleted file mode 100644 index 9abceb5f1e6..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsReifiedDisallow.jet +++ /dev/null @@ -1,3 +0,0 @@ -class MyList - -fun ff(l: MyList) = l is MyList diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsTraits.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsTraits.jet deleted file mode 100644 index 99656c2ab24..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsTraits.jet +++ /dev/null @@ -1,4 +0,0 @@ -trait Aaa -trait Bbb - -fun f(a: Aaa) = a is Bbb diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/WhenErasedDisallowFromAny.jet b/compiler/testData/checkerWithErrorTypes/full/cast/WhenErasedDisallowFromAny.jet deleted file mode 100644 index f38a4b14fbe..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/WhenErasedDisallowFromAny.jet +++ /dev/null @@ -1,6 +0,0 @@ -import java.util.List; - -fun ff(l: Any) = when(l) { - is List => 1 - else 2 -} diff --git a/compiler/testData/codegen/patternMatching/is.jet b/compiler/testData/codegen/patternMatching/is.jet index 9fac50c586b..a5b5f33195f 100644 --- a/compiler/testData/codegen/patternMatching/is.jet +++ b/compiler/testData/codegen/patternMatching/is.jet @@ -1,6 +1,6 @@ fun typeName(a: Any?) : String { return when(a) { - is java.util.ArrayList<*> => "array list" + is java.util.ArrayList => "array list" else => "no idea" } } @@ -8,4 +8,4 @@ fun typeName(a: Any?) : String { fun box() : String { if(typeName(java.util.ArrayList ()) != "array list") return "array list failed" return "OK" -} +} \ No newline at end of file From 97f377b529666188f6803948b890cc9bb6af990a Mon Sep 17 00:00:00 2001 From: svtk Date: Thu, 24 Nov 2011 15:58:25 +0400 Subject: [PATCH 07/17] Added "unused value analysis" --- .../cfg/JetControlFlowGraphTraverser.java | 3 +- .../lang/cfg/JetFlowInformationProvider.java | 65 ++++++++++++++++++- .../jet/lang/diagnostics/Errors.java | 13 ++++ .../jetbrains/jet/lang/psi/JetPsiUtil.java | 14 ++++ .../jet/lang/resolve/ControlFlowAnalyzer.java | 2 +- .../jet/plugin/annotations/JetPsiChecker.java | 3 + 6 files changed, 96 insertions(+), 4 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowGraphTraverser.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowGraphTraverser.java index 05171e2ad95..d9b090ff885 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowGraphTraverser.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowGraphTraverser.java @@ -36,7 +36,8 @@ public class JetControlFlowGraphTraverser { D initialDataValueForEnterInstruction, boolean straightDirection) { initializeDataMap(pseudocode, initialDataValue); - dataMap.put(pseudocode.getEnterInstruction(), Pair.create(initialDataValueForEnterInstruction, initialDataValueForEnterInstruction)); + dataMap.put(straightDirection ? pseudocode.getEnterInstruction() : pseudocode.getSinkInstruction(), + Pair.create(initialDataValueForEnterInstruction, initialDataValueForEnterInstruction)); boolean[] changed = new boolean[1]; changed[0] = true; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index 0af3af13785..426048e91fb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -5,6 +5,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiElement; +import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.cfg.pseudocode.*; @@ -274,7 +275,7 @@ public class JetFlowInformationProvider { boolean hasInitializer = !possiblePoints.isEmpty() || enterInitializationPoints.isInitialized(); if (possiblePoints.size() == 1) { JetElement initializer = possiblePoints.iterator().next(); - if (initializer == element.getParent()) { + if (initializer instanceof JetProperty && initializer == element.getParent()) { hasInitializer = false; } } @@ -402,13 +403,73 @@ public class JetFlowInformationProvider { for (VariableDescriptor declaredVariable : declaredVariables) { if (!usedVariables.contains(declaredVariable)) { PsiElement element = trace.get(BindingContext.DESCRIPTOR_TO_DECLARATION, declaredVariable); - if (element instanceof JetProperty) { + if (element instanceof JetProperty && JetPsiUtil.isLocal((JetProperty) element)) { PsiElement nameIdentifier = ((JetProperty) element).getNameIdentifier(); PsiElement elementToMark = nameIdentifier != null ? nameIdentifier : element; trace.report(Errors.UNUSED_VARIABLE.on((JetProperty)element, elementToMark, declaredVariable)); } } } + + markUnusedValues(subroutine, pseudocode, declaredVariables); + } + + private void markUnusedValues(@NotNull JetElement subroutine, Pseudocode pseudocode, final Collection declaredVariables) { + JetControlFlowGraphTraverser> traverser = JetControlFlowGraphTraverser.create(pseudocode, true); + traverser.collectInformationFromInstructionGraph(new JetControlFlowGraphTraverser.InstructionsMergeStrategy>() { + @Override + public Pair, Set> execute(Instruction instruction, @NotNull Collection> incomingEdgesData) { + Set enterResult = Sets.newHashSet(); + for (Set edgeData : incomingEdgesData) { + enterResult.addAll(edgeData); + } + Set exitResult = Sets.newHashSet(enterResult); + if (instruction instanceof ReadValueInstruction) { + VariableDescriptor variableDescriptor = extractVariableDescriptorIfAny(instruction, true); + if (variableDescriptor != null) { + exitResult.add(variableDescriptor); + } + } + else if (instruction instanceof WriteValueInstruction) { + VariableDescriptor variableDescriptor = extractVariableDescriptorIfAny(instruction, true); + if (variableDescriptor != null) { + exitResult.remove(variableDescriptor); + } + } + return new Pair, Set>(enterResult, exitResult); + } + }, Collections.emptySet(), Collections.emptySet(), false); + traverser.traverseAndAnalyzeInstructionGraph(new JetControlFlowGraphTraverser.InstructionDataAnalyzeStrategy>() { + @Override + public void execute(Instruction instruction, @Nullable Set enterData, @Nullable Set exitData) { + assert enterData != null && exitData != null; + if (instruction instanceof WriteValueInstruction) { + VariableDescriptor variableDescriptor = extractVariableDescriptorIfAny(instruction, false); + if (variableDescriptor != null && declaredVariables.contains(variableDescriptor)) { + if (!enterData.contains(variableDescriptor)) { + PsiElement variableDeclarationElement = trace.get(BindingContext.DESCRIPTOR_TO_DECLARATION, variableDescriptor); + assert variableDeclarationElement instanceof JetProperty || variableDeclarationElement instanceof JetParameter; + boolean isLocal = !(variableDeclarationElement instanceof JetProperty) || JetPsiUtil.isLocal((JetProperty) variableDeclarationElement); + if (isLocal) { + JetElement element = ((WriteValueInstruction) instruction).getElement(); + if (element instanceof JetBinaryExpression && ((JetBinaryExpression) element).getOperationToken() == JetTokens.EQ) { + JetExpression right = ((JetBinaryExpression) element).getRight(); + if (right != null) { + trace.report(Errors.UNUSED_VALUE.on(right, right, variableDescriptor)); + } + } + else if (element instanceof JetPostfixExpression) { + IElementType operationToken = ((JetPostfixExpression) element).getOperationSign().getReferencedNameElementType(); + if (operationToken == JetTokens.PLUSPLUS || operationToken == JetTokens.MINUSMINUS) { + trace.report(Errors.UNUSED_CHANGED_VALUE.on(element, element)); + } + } + } + } + } + } + } + }); } @Nullable diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index da7edd9d6fe..98f7f7d5d69 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -145,6 +145,19 @@ public interface Errors { PsiElementOnlyDiagnosticFactory1 UNINITIALIZED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME); PsiElementOnlyDiagnosticFactory1 UNUSED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(WARNING, "Variable ''{0}'' is never used", NAME); + PsiElementOnlyDiagnosticFactory2 UNUSED_VALUE = new PsiElementOnlyDiagnosticFactory2(WARNING, "The value ''{0}'' assigned to ''{1}'' is never used", NAME) { + @Override + protected String makeMessageForA(@NotNull JetElement element) { + return element.getText(); + } + }; + PsiElementOnlyDiagnosticFactory1 UNUSED_CHANGED_VALUE = new PsiElementOnlyDiagnosticFactory1(WARNING, "The value changed at ''{0}'' is never used", NAME) { + @Override + protected String makeMessageFor(JetElement argument) { + return argument.getText(); + } + }; + PsiElementOnlyDiagnosticFactory2 VAL_REASSIGNMENT = new PsiElementOnlyDiagnosticFactory2(ERROR, "Val can not be reassigned", NAME) { @NotNull @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java index 353ea233095..0fb77fc8703 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -1,6 +1,7 @@ package org.jetbrains.jet.lang.psi; import com.intellij.psi.PsiElement; +import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lexer.JetTokens; @@ -102,4 +103,17 @@ public class JetPsiUtil { return unquoteIdentifier(quoted); } } + + public static boolean isLocal(@NotNull JetProperty property) { + JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(property, JetClassOrObject.class); + JetDeclarationWithBody function = PsiTreeUtil.getParentOfType(property, JetDeclarationWithBody.class); + if (function != null && PsiTreeUtil.isAncestor(classOrObject, function, false)) { + return true; + } + if (classOrObject != null && PsiTreeUtil.isAncestor(function, classOrObject, false)) { + return false; + } + if (function != null) return true; + return false; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java index c8fbeafee31..96d09dce0bc 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java @@ -84,6 +84,6 @@ public class ControlFlowAnalyzer { flowInformationProvider.markUninitializedVariables(function.asElement(), false, inLocalDeclaration); -// flowInformationProvider.markUnusedVariables(function.asElement()); + flowInformationProvider.markUnusedVariables(function.asElement()); } } diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java index 17353d877d8..09f872108fc 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java @@ -88,6 +88,9 @@ public class JetPsiChecker implements Annotator { } else if (diagnostic.getSeverity() == Severity.WARNING) { annotation = holder.createWarningAnnotation(diagnostic.getFactory().getTextRange(diagnostic), getMessage(diagnostic)); + if (diagnostic.getFactory() == Errors.UNUSED_VARIABLE) { + annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL); + } } if (annotation != null) { if (diagnostic instanceof DiagnosticWithPsiElementImpl && diagnostic.getFactory() instanceof PsiElementOnlyDiagnosticFactory) { From a7bb30a18c32a0ceae963f17cd2c6d12769289d5 Mon Sep 17 00:00:00 2001 From: svtk Date: Thu, 24 Nov 2011 15:59:44 +0400 Subject: [PATCH 08/17] "Unused value" error added to existed tests --- .../checkerWithErrorTypes/full/Abstract.jet | 4 +- .../full/AnonymousInitializers.jet | 2 +- .../full/ExtensionFunctions.jet | 2 +- .../full/FunctionReturnTypes.jet | 16 +- .../checkerWithErrorTypes/full/IncDec.jet | 12 +- .../full/QualifiedExpressions.jet | 10 +- .../full/QualifiedThis.jet | 8 +- .../full/ResolveToJava.jet | 16 +- .../checkerWithErrorTypes/full/Unresolved.jet | 8 +- .../checkerWithErrorTypes/full/Variance.jet | 8 +- .../full/infos/Autocasts.jet | 28 ++-- .../regression/AssignmentsUnderOperators.jet | 2 +- .../full/regression/CoercionToUnit.jet | 2 +- .../full/regression/DoubleDefine.jet | 4 +- .../full/regression/Jet124.jet | 4 +- .../full/regression/Jet183.jet | 4 +- .../ScopeForSecondaryConstructors.jet | 7 +- .../quick/AutocastsForStableIdentifiers.jet | 34 ++--- .../checkerWithErrorTypes/quick/Basic.jet | 2 +- .../quick/IncorrectCharacterLiterals.jet | 13 +- .../quick/SafeCallNonNullReceiver.jet | 4 +- .../SafeCallNonNullReceiverReturnNull.jet | 4 +- .../checkerWithErrorTypes/quick/Super.jet | 2 +- .../quick/TypeInference.jet | 18 +-- .../UninitializedOrReassignedVariables.jet | 20 +-- .../quick/UnitByDefaultForFunctionTypes.jet | 2 +- .../quick/UnusedVariables.jet | 142 ++++++++++++++++++ .../quick/regressions/kt235.jet | 16 +- .../quick/regressions/kt352.jet | 2 +- .../quick/regressions/kt353.jet | 10 +- .../quick/regressions/kt411.jet | 8 +- .../quick/regressions/kt442.jet | 6 +- .../kt526UnresolvedReferenceInnerStatic.jet | 5 +- .../jet/checkers/CheckerTestUtilTest.java | 2 +- idea/testData/checker/Abstract.jet | 4 +- .../checker/AnonymousInitializers.jet | 2 +- idea/testData/checker/ExtensionFunctions.jet | 2 +- idea/testData/checker/IncDec.jet | 6 +- .../testData/checker/QualifiedExpressions.jet | 10 +- idea/testData/checker/QualifiedThis.jet | 6 +- idea/testData/checker/ResolveToJava.jet | 14 +- idea/testData/checker/Unresolved.jet | 6 +- idea/testData/checker/Variance.jet | 6 +- idea/testData/checker/infos/Autocasts.jet | 28 ++-- idea/testData/checker/infos/WrapIntoRef.jet | 20 +-- .../regression/AssignmentsUnderOperators.jet | 2 +- .../checker/regression/CoercionToUnit.jet | 2 +- .../checker/regression/DoubleDefine.jet | 2 +- idea/testData/checker/regression/Jet124.jet | 4 +- idea/testData/checker/regression/Jet183.jet | 2 +- .../ScopeForSecondaryConstructors.jet | 2 +- 51 files changed, 342 insertions(+), 203 deletions(-) create mode 100644 compiler/testData/checkerWithErrorTypes/quick/UnusedVariables.jet diff --git a/compiler/testData/checkerWithErrorTypes/full/Abstract.jet b/compiler/testData/checkerWithErrorTypes/full/Abstract.jet index e1633f74b05..ce355f02045 100644 --- a/compiler/testData/checkerWithErrorTypes/full/Abstract.jet +++ b/compiler/testData/checkerWithErrorTypes/full/Abstract.jet @@ -236,6 +236,6 @@ abstract class B3(i: Int) { } fun foo(a: B3) { - val a = B3() - val b = B1(2, "s") + val a = B3() + val b = B1(2, "s") } \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/AnonymousInitializers.jet b/compiler/testData/checkerWithErrorTypes/full/AnonymousInitializers.jet index 955798a7a9c..74efce233c3 100644 --- a/compiler/testData/checkerWithErrorTypes/full/AnonymousInitializers.jet +++ b/compiler/testData/checkerWithErrorTypes/full/AnonymousInitializers.jet @@ -28,7 +28,7 @@ class WithC() { } this(a : Int) : this() { - val b = x + val b = x } } \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/ExtensionFunctions.jet b/compiler/testData/checkerWithErrorTypes/full/ExtensionFunctions.jet index d12496d9e8b..141e47ae591 100644 --- a/compiler/testData/checkerWithErrorTypes/full/ExtensionFunctions.jet +++ b/compiler/testData/checkerWithErrorTypes/full/ExtensionFunctions.jet @@ -28,7 +28,7 @@ fun A.plus(a : Int) { fun T.minus(t : T) : Int = 1 fun test() { - val y = 1.abs + val y = 1.abs } val Int.abs : Int get() = if (this > 0) this else -this; diff --git a/compiler/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet b/compiler/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet index 0cd9f099e25..850cb2fd5e0 100644 --- a/compiler/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet +++ b/compiler/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet @@ -116,7 +116,7 @@ fun blockReturnValueTypeMatch12() : Int { else return 1.0 } fun blockNoReturnIfValDeclaration(): Int { - val x = 1 + val x = 1 } fun blockNoReturnIfEmptyIf(): Int { if (1 < 2) {} else {} @@ -174,37 +174,37 @@ class B() { } fun testFunctionLiterals() { - val endsWithVarDeclaration : fun() : Boolean = { + val endsWithVarDeclaration : fun() : Boolean = { val x = 2 } - val endsWithAssignment = { () : Int => + val endsWithAssignment = { () : Int => var x = 1 x = 333 } - val endsWithReAssignment = { () : Int => + val endsWithReAssignment = { () : Int => var x = 1 x += 333 } - val endsWithFunDeclaration : fun() : String = { + val endsWithFunDeclaration : fun() : String = { var x = 1 x = 333 fun meow() : Unit {} } - val endsWithObjectDeclaration : fun() : Int = { + val endsWithObjectDeclaration : fun() : Int = { var x = 1 x = 333 object A {} } - val expectedUnitReturnType1 = { () : Unit => + val expectedUnitReturnType1 = { () : Unit => val x = 1 } - val expectedUnitReturnType2 = { () : Unit => + val expectedUnitReturnType2 = { () : Unit => fun meow() : Unit {} object A {} } diff --git a/compiler/testData/checkerWithErrorTypes/full/IncDec.jet b/compiler/testData/checkerWithErrorTypes/full/IncDec.jet index 5b7143f3eef..f0cab587ec0 100644 --- a/compiler/testData/checkerWithErrorTypes/full/IncDec.jet +++ b/compiler/testData/checkerWithErrorTypes/full/IncDec.jet @@ -9,10 +9,10 @@ fun testIncDec() { ++x x-- --x - x = x++ - x = x-- + x = x++ + x = x-- x = ++x - x = --x + x = --x } class WrongIncDec() { @@ -39,8 +39,8 @@ fun testUnitIncDec() { ++x x-- --x - x = x++ - x = x-- + x = x++ + x = x-- x = ++x - x = --x + x = --x } \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/QualifiedExpressions.jet b/compiler/testData/checkerWithErrorTypes/full/QualifiedExpressions.jet index 67233fd840f..187c745ef63 100644 --- a/compiler/testData/checkerWithErrorTypes/full/QualifiedExpressions.jet +++ b/compiler/testData/checkerWithErrorTypes/full/QualifiedExpressions.jet @@ -1,11 +1,11 @@ namespace qualified_expressions fun test(s: String?) { - val a: Int = s?.length + val a: Int = s?.length val b: Int? = s?.length - val c: Int = s?.length ?: -11 - val d: Int = s?.length ?: "empty" + val c: Int = s?.length ?: -11 + val d: Int = s?.length ?: "empty" val e: String = s?.length ?: "empty" - val f: Int = s?.length ?: b ?: 1 - val g: Int? = e? startsWith("s")?.length + val f: Int = s?.length ?: b ?: 1 + val g: Int? = e? startsWith("s")?.length } \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/QualifiedThis.jet b/compiler/testData/checkerWithErrorTypes/full/QualifiedThis.jet index f23c01cfd20..7fab8479b4b 100644 --- a/compiler/testData/checkerWithErrorTypes/full/QualifiedThis.jet +++ b/compiler/testData/checkerWithErrorTypes/full/QualifiedThis.jet @@ -31,11 +31,11 @@ namespace closures { val Int.xx = this : Int fun Char.xx() : Any { this : Char - val a = {Double.() => this : Double + this@xx : Char} - val b = @a{Double.() => this@a : Double + this@xx : Char} - val c = @a{() => this@a + this@xx : Char} + val a = {Double.() => this : Double + this@xx : Char} + val b = @a{Double.() => this@a : Double + this@xx : Char} + val c = @a{() => this@a + this@xx : Char} return (@a{Double.() => this@a : Double + this@xx : Char}) } } } -} +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/ResolveToJava.jet b/compiler/testData/checkerWithErrorTypes/full/ResolveToJava.jet index e2385007530..61483f8ea48 100644 --- a/compiler/testData/checkerWithErrorTypes/full/ResolveToJava.jet +++ b/compiler/testData/checkerWithErrorTypes/full/ResolveToJava.jet @@ -8,13 +8,13 @@ import java.lang.Comparable as Com val l : List = ArrayList() fun test(l : java.util.List) { - val x : java.List - val y : java.util.List - val b : java.lang.Object - val a : util.List - val z : java.utils.List + val x : java.List + val y : java.util.List + val b : java.lang.Object + val a : util.List + val z : java.utils.List - val f : java.io.File? = null + val f : java.io.File? = null Collections.emptyList Collections.emptyList @@ -27,7 +27,7 @@ fun test(l : java.util.List) { List - val o = "sdf" as Object + val o = "sdf" as Object try { // ... @@ -49,4 +49,4 @@ fun test(l : java.util.List) { namespace xxx { import java.lang.Class; -} +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/Unresolved.jet b/compiler/testData/checkerWithErrorTypes/full/Unresolved.jet index 9bd749a8372..a13dae7809b 100644 --- a/compiler/testData/checkerWithErrorTypes/full/Unresolved.jet +++ b/compiler/testData/checkerWithErrorTypes/full/Unresolved.jet @@ -1,13 +1,13 @@ namespace unresolved fun testGenericArgumentsCount() { - val p1: Tuple2 = (2, 2) - val p2: Tuple2 = (2, 2) + val p1: Tuple2 = (2, 2) + val p2: Tuple2 = (2, 2) } fun testUnresolved() { if (a is String) { - val s = a + val s = a } foo(a) val s = "s" @@ -28,4 +28,4 @@ fun testUnresolved() { } } -fun foo1(i: Int) {} +fun foo1(i: Int) {} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/Variance.jet b/compiler/testData/checkerWithErrorTypes/full/Variance.jet index 0607a6f0a13..1306c251f00 100644 --- a/compiler/testData/checkerWithErrorTypes/full/Variance.jet +++ b/compiler/testData/checkerWithErrorTypes/full/Variance.jet @@ -8,13 +8,13 @@ abstract class Usual {} fun foo(c: Consumer, p: Producer, u: Usual) { val c1: Consumer = c - val c2: Consumer = c1 + val c2: Consumer = c1 val p1: Producer = p - val p2: Producer = p1 + val p2: Producer = p1 val u1: Usual = u - val u2: Usual = u1 + val u2: Usual = u1 } //Arrays copy example @@ -37,4 +37,4 @@ fun f(ints: Array, any: Array, numbers: Array) { copy2(ints, numbers) copy3(ints, numbers) copy4(ints, numbers) //ok -} +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/infos/Autocasts.jet b/compiler/testData/checkerWithErrorTypes/full/infos/Autocasts.jet index 0d4a237a116..de468b149b4 100644 --- a/compiler/testData/checkerWithErrorTypes/full/infos/Autocasts.jet +++ b/compiler/testData/checkerWithErrorTypes/full/infos/Autocasts.jet @@ -165,42 +165,42 @@ fun illegalWhenBlock(a: Any): Int { } fun declarations(a: Any?) { if (a is String) { - val p4: (Int, String) = (2, a) + val p4: (Int, String) = (2, a) } if (a is String?) { if (a != null) { - val s: String = a + val s: String = a } } if (a != null) { if (a is String?) { - val s: String = a + val s: String = a } } } fun vars(a: Any?) { - var b: Int = 0 + var b: Int = 0 if (a is Int) { - b = a + b = a } } fun tuples(a: Any?) { if (a != null) { - val s: (Any, String) = (a, a) + val s: (Any, String) = (a, a) } if (a is String) { - val s: (Any, String) = (a, a) + val s: (Any, String) = (a, a) } fun illegalTupleReturnType(): (Any, String) = (a, a) if (a is String) { fun legalTupleReturnType(): (Any, String) = (a, a) } - val illegalFunctionLiteral: Function0 = { a } - val illegalReturnValueInFunctionLiteral: Function0 = { (): Int => a } + val illegalFunctionLiteral: Function0 = { a } + val illegalReturnValueInFunctionLiteral: Function0 = { (): Int => a } if (a is Int) { - val legalFunctionLiteral: Function0 = { a } - val alsoLegalFunctionLiteral: Function0 = { (): Int => a } + val legalFunctionLiteral: Function0 = { a } + val alsoLegalFunctionLiteral: Function0 = { (): Int => a } } } fun returnFunctionLiteralBlock(a: Any?): Function0 { @@ -227,7 +227,7 @@ fun mergeAutocasts(a: Any?) { is String, is Any => a.compareTo("") } if (a is String && a is Any) { - val i: Int = a.compareTo("") + val i: Int = a.compareTo("") } if (a is String && a.compareTo("") == 0) {} if (a is String || a.compareTo("") == 0) {} @@ -237,9 +237,9 @@ fun mergeAutocasts(a: Any?) { fun f(): String { var a: Any = 11 if (a is String) { - val i: String = a + val i: String = a a.compareTo("f") - val f: Function0 = { a } + val f: Function0 = { a } return a } return "" diff --git a/compiler/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet b/compiler/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet index 2acdbfdd984..43f56b9465e 100644 --- a/compiler/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet +++ b/compiler/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet @@ -2,5 +2,5 @@ fun test() { var a : Any? = null if (a is Any) else a = null; while (a is Any) a = null - while (true) a = null + while (true) a = null } \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/regression/CoercionToUnit.jet b/compiler/testData/checkerWithErrorTypes/full/regression/CoercionToUnit.jet index 6733ab3a31e..6ce84f8c66b 100644 --- a/compiler/testData/checkerWithErrorTypes/full/regression/CoercionToUnit.jet +++ b/compiler/testData/checkerWithErrorTypes/full/regression/CoercionToUnit.jet @@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1 fun test() : Int { foo(1) - val a : fun() : Unit = { + val a : fun() : Unit = { foo(1) } return 1 diff --git a/compiler/testData/checkerWithErrorTypes/full/regression/DoubleDefine.jet b/compiler/testData/checkerWithErrorTypes/full/regression/DoubleDefine.jet index fbca6a41c99..996c4608778 100644 --- a/compiler/testData/checkerWithErrorTypes/full/regression/DoubleDefine.jet +++ b/compiler/testData/checkerWithErrorTypes/full/regression/DoubleDefine.jet @@ -32,7 +32,7 @@ fun evaluateAdd(expr: StringBuilder, numbers: ArrayList): Int { fun evaluate(expr: StringBuilder, numbers: ArrayList): Int { val lhs = evaluateAdd(expr, numbers) if (expr.length() > 0) { - val c = expr.charAt(0) + val c = expr.charAt(0) expr.deleteCharAt(0) } return lhs @@ -63,4 +63,4 @@ fun main(args: Array) { catch(e: Throwable) { System.out?.println(e.getMessage()) } -} +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/regression/Jet124.jet b/compiler/testData/checkerWithErrorTypes/full/regression/Jet124.jet index 317b1438f41..58e876a80f2 100644 --- a/compiler/testData/checkerWithErrorTypes/full/regression/Jet124.jet +++ b/compiler/testData/checkerWithErrorTypes/full/regression/Jet124.jet @@ -1,8 +1,8 @@ fun foo1() : fun (Int) : Int = { (x: Int) => x } fun foo() { - val h : fun (Int) : Int = foo1(); + val h : fun (Int) : Int = foo1(); h(1) - val m : fun (Int) : Int = {(a : Int) => 1}//foo1() + val m : fun (Int) : Int = {(a : Int) => 1}//foo1() m(1) } \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/regression/Jet183.jet b/compiler/testData/checkerWithErrorTypes/full/regression/Jet183.jet index 59df6e106d6..a6992d2c8e3 100644 --- a/compiler/testData/checkerWithErrorTypes/full/regression/Jet183.jet +++ b/compiler/testData/checkerWithErrorTypes/full/regression/Jet183.jet @@ -18,5 +18,5 @@ enum class Foo { fun box() { - val x: ProtocolState = ProtocolState.WAITING -} + val x: ProtocolState = ProtocolState.WAITING +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/full/regression/ScopeForSecondaryConstructors.jet b/compiler/testData/checkerWithErrorTypes/full/regression/ScopeForSecondaryConstructors.jet index 80b5a321d89..31212378979 100644 --- a/compiler/testData/checkerWithErrorTypes/full/regression/ScopeForSecondaryConstructors.jet +++ b/compiler/testData/checkerWithErrorTypes/full/regression/ScopeForSecondaryConstructors.jet @@ -1,4 +1,4 @@ - class Foo(var bar : Int, var barr : Int, var barrr : Int) { +class Foo(var bar : Int, var barr : Int, var barrr : Int) { { bar = 1 barr = 1 @@ -11,8 +11,7 @@ bar = 1 this.bar 1 : Int - val a : Int =1 + val a : Int =1 this : Foo } - } - + } \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/AutocastsForStableIdentifiers.jet b/compiler/testData/checkerWithErrorTypes/quick/AutocastsForStableIdentifiers.jet index 6bb9d5f51db..37ff349686f 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/AutocastsForStableIdentifiers.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/AutocastsForStableIdentifiers.jet @@ -17,42 +17,42 @@ class AClass() { val x : Any? = 1 fun Any?.vars(a: Any?) : Int { - var b: Int = 0 + var b: Int = 0 if (ns.y is Int) { - b = ns.y + b = ns.y } if (ns.y is Int) { - b = example.ns.y + b = example.ns.y } if (example.ns.y is Int) { - b = ns.y + b = ns.y } if (example.ns.y is Int) { - b = example.ns.y + b = example.ns.y } // if (namespace.bottles.ns.y is Int) { // b = ns.y // } if (Obj.y is Int) { - b = Obj.y + b = Obj.y } if (example.Obj.y is Int) { - b = Obj.y + b = Obj.y } if (AClass.y is Int) { - b = AClass.y + b = AClass.y } if (example.AClass.y is Int) { - b = AClass.y + b = AClass.y } if (x is Int) { - b = x + b = x } if (example.x is Int) { - b = x + b = x } if (example.x is Int) { - b = example.x + b = example.x } return 1 } @@ -74,18 +74,18 @@ trait T {} open class C { fun foo() { - var t : T? = null + var t : T? = null if (this is T) { - t = this + t = this } if (this is T) { - t = this@C + t = this@C } if (this@C is T) { - t = this + t = this } if (this@C is T) { - t = this@C + t = this@C } } } \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/Basic.jet b/compiler/testData/checkerWithErrorTypes/quick/Basic.jet index dea3b44a6e1..82775571c83 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/Basic.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/Basic.jet @@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1 fun test() : Int { foo(1) - val a : fun() : Unit = { + val a : fun() : Unit = { foo(1) } return 1 - "1" diff --git a/compiler/testData/checkerWithErrorTypes/quick/IncorrectCharacterLiterals.jet b/compiler/testData/checkerWithErrorTypes/quick/IncorrectCharacterLiterals.jet index d30fa5f45f7..aee64608f0d 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/IncorrectCharacterLiterals.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/IncorrectCharacterLiterals.jet @@ -2,11 +2,11 @@ // KT-451 Incorrect character literals cause assertion failures fun ff() { - val b = '' - val c = '23' - val d = 'a - val e = 'ab - val f = '\' + val b = '' + val c = '23' + val d = 'a + val e = 'ab + val f = '\' } fun test() { @@ -34,5 +34,4 @@ fun test() { '\u000z' '\\u000' '\' -} - +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/SafeCallNonNullReceiver.jet b/compiler/testData/checkerWithErrorTypes/quick/SafeCallNonNullReceiver.jet index 5157eb39277..8cb0f3c0e86 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/SafeCallNonNullReceiver.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/SafeCallNonNullReceiver.jet @@ -2,5 +2,5 @@ fun ff() { val i: Int = 1 - val a: Int = i?.plus(2) -} + val a: Int = i?.plus(2) +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/SafeCallNonNullReceiverReturnNull.jet b/compiler/testData/checkerWithErrorTypes/quick/SafeCallNonNullReceiverReturnNull.jet index fe6d5efeeed..f56ba89b746 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/SafeCallNonNullReceiverReturnNull.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/SafeCallNonNullReceiverReturnNull.jet @@ -2,5 +2,5 @@ fun Int.gg() = null fun ff() { val a: Int = 1 - val b: Int = a?.gg() -} + val b: Int = a?.gg() +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/Super.jet b/compiler/testData/checkerWithErrorTypes/quick/Super.jet index 5841b9108f3..7a3095d820f 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/Super.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/Super.jet @@ -5,7 +5,7 @@ fun any(a : Any) {} fun notAnExpression() { any(super) // not an expression if (super) {} else {} // not an expression - val x = super // not an expression + val x = super // not an expression when (1) { super => 1 // not an expression } diff --git a/compiler/testData/checkerWithErrorTypes/quick/TypeInference.jet b/compiler/testData/checkerWithErrorTypes/quick/TypeInference.jet index ed8093219b0..5f35e4d98a5 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/TypeInference.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/TypeInference.jet @@ -6,13 +6,13 @@ fun foo(c: C) {} fun bar() : C {} fun main(args : Array) { - val a : C = C(); - val x : C = C() - val y : C = C() - val z : C<*> = C() + val a : C = C(); + val x : C = C() + val y : C = C() + val z : C<*> = C() - val ba : C = bar(); - val bx : C = bar() - val by : C = bar() - val bz : C<*> = bar() -} + val ba : C = bar(); + val bx : C = bar() + val by : C = bar() + val bz : C<*> = bar() +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/UninitializedOrReassignedVariables.jet b/compiler/testData/checkerWithErrorTypes/quick/UninitializedOrReassignedVariables.jet index 17ddcc58a79..63739b20d4b 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/UninitializedOrReassignedVariables.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/UninitializedOrReassignedVariables.jet @@ -63,11 +63,11 @@ fun t4(a: A, val b: A, var c: A) { // reassigned vals fun t1() { - val a : Int = 1 - a = 2 + val a : Int = 1 + a = 2 - var b : Int = 1 - b = 3 + var b : Int = 1 + b = 3 } abstract enum class ProtocolState { @@ -85,7 +85,7 @@ abstract enum class ProtocolState { fun t3() { val x: ProtocolState = ProtocolState.WAITING x = x.signal() - x = x.signal() //repeat for x + x = x.signal() //repeat for x } fun t4() { @@ -265,7 +265,7 @@ class ClassObject() { } fun foo() { - val a = object { + val a = object { val x : Int val y : Int val z : Int @@ -283,7 +283,7 @@ fun foo() { class TestObjectExpression() { val a : Int fun foo() { - val a = object { + val a = object { val x : Int val y : Int { @@ -325,10 +325,10 @@ object TestObjectDeclaration { fun func() { val b = 1 - val a = object { + val a = object { val x = b { - b = 4 + b = 4 $b = 3 } } @@ -349,4 +349,4 @@ fun test(m : M) { fun test1(m : M) { m.x++ m.y-- -} +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/UnitByDefaultForFunctionTypes.jet b/compiler/testData/checkerWithErrorTypes/quick/UnitByDefaultForFunctionTypes.jet index 383e67e16c4..9a14ad7a471 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/UnitByDefaultForFunctionTypes.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/UnitByDefaultForFunctionTypes.jet @@ -1,3 +1,3 @@ fun foo(f : fun()) { - val x : Unit = f() + val x : Unit = f() } \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/UnusedVariables.jet b/compiler/testData/checkerWithErrorTypes/quick/UnusedVariables.jet new file mode 100644 index 00000000000..c52c8e8e61d --- /dev/null +++ b/compiler/testData/checkerWithErrorTypes/quick/UnusedVariables.jet @@ -0,0 +1,142 @@ +namespace unused_variables + +fun testSimpleCases() { + var i = 2 + i = 34 + i = 34 + doSmth(i) + i = 5 + + var j = 2 + j = j++ + j = j-- +} + +class IncDec() { + fun inc() : IncDec = this + fun dec() : IncDec = this +} + +class MyTest() { + fun testIncDec() { + var x = IncDec() + x++ + ++x + x-- + --x + x = x++ + x = x-- + x = ++x + x = --x + } + + var a: String = "s" + set(v: String) { + var i: Int = 23 + doSmth(i) + i = 34 + $a = v + } + + { + a = "rr" + } + + fun testSimple() { + a = "rro" + + var i = 1; + i = 34; + i = 456; + } + + fun testWhile(a : Any?, b : Any?) { + var a : Any? = true + var b : Any? = 34 + while (a is Any) { + a = null + } + while (b != null) { + a = null + } + } + + fun testIf() { + var a : Any + if (1 < 2) { + a = 23 + } + else { + a = "ss" + doSmth(a as String) + } + doSmth(a) + + if (1 < 2) { + a = 23 + } + else { + a = "ss" + } + } + + fun testFor() { + for (i in 1..10) { + doSmth(i) + } + } + + fun doSmth(s: String) {} + fun doSmth(a: Any) {} +} + +fun testInnerFunctions() { + var y = 1 + fun foo() { + y = 1 + } + var z = 1 + fun bar() { + doSmth(z) + } +} + +fun testFunctionLiterals() { + var x = 1 + var fl = { (): Int => + x + } + var y = 2 + var fl1 = { (): Unit => + doSmth(y) + } +} + +trait Trait { + fun foo() +} + +fun testObject() : Trait { + val x = 24 + val o = object : Trait { + val y : Int //in this case y should not be marked as unused + get() = 55 + + override fun foo() { + doSmth(x) + } + } + + return o +} + +fun testBackingFieldsNotMarked() { + val a = object { + val x : Int + { + $x = 1 + } + } +} + +fun doSmth(i : Int) {} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt235.jet b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt235.jet index 5e4f6a0cd9b..7420cb938e5 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt235.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt235.jet @@ -4,33 +4,33 @@ namespace kt235 fun main(args: Array) { val array = MyArray() - val f = { (): String => + val f = { (): String => array[2] = 23 //error: Type mismatch: inferred type is Int (!!!) but String was expected } - val g = {(): String => + val g = {(): String => var x = 1 x += 2 //no error, but it should be here } - val h = {(): String => + val h = {(): String => var x = 1 x = 2 //the same } val array1 = MyArray1() - val x = { (): String => + val x = { (): String => array1[2] = 23 } - val fi = { (): Int => + val fi = { (): Int => array[2] = 23 } - val gi = {(): Int => + val gi = {(): Int => var x = 1 x += 21 } var m: MyNumber = MyNumber() - val a = { (): MyNumber => - m++ + val a = { (): MyNumber => + m++ } } diff --git a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt352.jet b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt352.jet index da402197d5f..e9b4eb34e94 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt352.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt352.jet @@ -5,7 +5,7 @@ namespace kt352 val f : fun(Any) : Unit = { () : Unit => } //type mismatch fun foo() { - val f : fun(Any) : Unit = { () : Unit => } //!!! no error + val f : fun(Any) : Unit = { () : Unit => } //!!! no error } class A() { diff --git a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt353.jet b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt353.jet index 5a7c9569795..dffdaa68d48 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt353.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt353.jet @@ -5,17 +5,17 @@ trait A { } fun foo(a: A) { - val g : fun() : Unit = { + val g : fun() : Unit = { a.gen() //it works: Unit is derived } - val u: Unit = a.gen() //type mismatch, but Unit can be derived + val u: Unit = a.gen() //type mismatch, but Unit can be derived if (true) { a.gen() //it works: Unit is derived } - val b : fun() : Unit = { + val b : fun() : Unit = { if (true) { a.gen() //type mismatch, but Unit can be derived } @@ -24,9 +24,9 @@ fun foo(a: A) { } } - val f : fun() : Int = { () : Int => + val f : fun() : Int = { () : Int => a.gen() //type mismatch, but Int can be derived } a.gen() //it works: Unit is derived -} +} \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt411.jet b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt411.jet index aed23ee9382..5d724d405da 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt411.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt411.jet @@ -13,13 +13,13 @@ fun invoker(gen : fun() : Int) : Int = 0 //more tests fun t1() { - val v = @{ () : Int => + val v = @{ () : Int => return@ 111 } } fun t2() : String { - val g : fun(): Int = @{ + val g : fun(): Int = @{ if (true) { return@ 1 } @@ -54,10 +54,10 @@ fun t3() : String { } fun t4() : Int { - val h : fun (): String = @l{ + val h : fun (): String = @l{ return@l "a" } - val g : fun (): String = @{ () : String => + val g : fun (): String = @{ () : String => return@ "a" } diff --git a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt442.jet b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt442.jet index 3138ed71587..79390466a35 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt442.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt442.jet @@ -3,13 +3,13 @@ fun funny(f : fun() : T) : T = f() fun testFunny() { - val a : Int = funny {1} + val a : Int = funny {1} } fun funny2(f : fun(t : T) : T) : T {} fun testFunny2() { - val a : Int = funny2 {it} + val a : Int = funny2 {it} } fun box() : String { @@ -25,7 +25,7 @@ fun T.with(f : fun T.()) { } fun main(args : Array) { - val a = 1 with { + val a = 1 with { plus(1) } } \ No newline at end of file diff --git a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt526UnresolvedReferenceInnerStatic.jet b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt526UnresolvedReferenceInnerStatic.jet index b918b0d4c17..b258404a6f6 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt526UnresolvedReferenceInnerStatic.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt526UnresolvedReferenceInnerStatic.jet @@ -10,7 +10,6 @@ class Foo { } class User { fun main() : Unit { - var boo : Foo.Bar? /* <-- this reference is red */ = Foo.Bar() + var boo : Foo.Bar? /* <-- this reference is red */ = Foo.Bar() } -} - +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java b/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java index 06ffed74d04..cdf385d3158 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java @@ -67,7 +67,7 @@ public class CheckerTestUtilTest extends JetLiteFixture { doTest(new TheTest("Unexpected NONE_APPLICABLE at 122 to 123", "Missing TYPE_MISMATCH at 161 to 169") { @Override protected void makeTestData(List diagnostics, List diagnosedRanges) { - diagnosedRanges.remove(2); + diagnosedRanges.remove(3); diagnostics.remove(diagnostics.size() - 3); } }); diff --git a/idea/testData/checker/Abstract.jet b/idea/testData/checker/Abstract.jet index ca35e2bac53..4c34620c5e5 100644 --- a/idea/testData/checker/Abstract.jet +++ b/idea/testData/checker/Abstract.jet @@ -161,6 +161,6 @@ abstract class B3(i: Int) { } fun foo(a: B3) { - val a = B3() - val b = B1(2, "s") + val a = B3() + val b = B1(2, "s") } \ No newline at end of file diff --git a/idea/testData/checker/AnonymousInitializers.jet b/idea/testData/checker/AnonymousInitializers.jet index d579cb6f7c8..f5f5db7a224 100644 --- a/idea/testData/checker/AnonymousInitializers.jet +++ b/idea/testData/checker/AnonymousInitializers.jet @@ -28,7 +28,7 @@ class WithC() { } this(a : Int) : this() { - val b = x + val b = x } } \ No newline at end of file diff --git a/idea/testData/checker/ExtensionFunctions.jet b/idea/testData/checker/ExtensionFunctions.jet index f1ec6d22908..3fd3dcffbfb 100644 --- a/idea/testData/checker/ExtensionFunctions.jet +++ b/idea/testData/checker/ExtensionFunctions.jet @@ -28,7 +28,7 @@ fun A.plus(a : Int) { fun T.minus(t : T) : Int = 1 fun test() { - val y = 1.abs + val y = 1.abs } val Int.abs : Int get() = if (this > 0) this else -this; diff --git a/idea/testData/checker/IncDec.jet b/idea/testData/checker/IncDec.jet index 6d562f2ed03..aa46004ffc2 100644 --- a/idea/testData/checker/IncDec.jet +++ b/idea/testData/checker/IncDec.jet @@ -9,10 +9,10 @@ fun testIncDec() { ++x x-- --x - x = x++ - x = x-- + x = x++ + x = x-- x = ++x - x = --x + x = --x } class WrongIncDec() { diff --git a/idea/testData/checker/QualifiedExpressions.jet b/idea/testData/checker/QualifiedExpressions.jet index 0ef138d7cd5..351e15e0e4e 100644 --- a/idea/testData/checker/QualifiedExpressions.jet +++ b/idea/testData/checker/QualifiedExpressions.jet @@ -1,11 +1,11 @@ namespace qualified_expressions fun test(s: String?) { - val a: Int = s?.length + val a: Int = s?.length val b: Int? = s?.length - val c: Int = s?.length ?: -11 - val d: Int = s?.length ?: "empty" + val c: Int = s?.length ?: -11 + val d: Int = s?.length ?: "empty" val e: String = s?.length ?: "empty" - val f: Int = s?.length ?: b ?: 1 - val g: Int? = e? startsWith("s")?.length + val f: Int = s?.length ?: b ?: 1 + val g: Int? = e? startsWith("s")?.length } \ No newline at end of file diff --git a/idea/testData/checker/QualifiedThis.jet b/idea/testData/checker/QualifiedThis.jet index 37a1f0d90d3..c0825aa37c1 100644 --- a/idea/testData/checker/QualifiedThis.jet +++ b/idea/testData/checker/QualifiedThis.jet @@ -31,9 +31,9 @@ namespace closures { val Int.xx = this : Int fun Char.xx() : Any { this : Char - val a = {Double.() => this : Double + this@xx : Char} - val b = @a{Double.() => this@a : Double + this@xx : Char} - val c = @a{() => this@a + this@xx : Char} + val a = {Double.() => this : Double + this@xx : Char} + val b = @a{Double.() => this@a : Double + this@xx : Char} + val c = @a{() => this@a + this@xx : Char} return (@a{Double.() => this@a : Double + this@xx : Char}) } } diff --git a/idea/testData/checker/ResolveToJava.jet b/idea/testData/checker/ResolveToJava.jet index 215e9561ffe..17eafa7b2d8 100644 --- a/idea/testData/checker/ResolveToJava.jet +++ b/idea/testData/checker/ResolveToJava.jet @@ -8,13 +8,13 @@ import java.lang.Comparable as Com val l : List = ArrayList() fun test(l : java.util.List) { - val x : java.List - val y : java.util.List - val b : java.lang.Object - val a : util.List - val z : java.utils.List + val x : java.List + val y : java.util.List + val b : java.lang.Object + val a : util.List + val z : java.utils.List - val f : java.io.File? = null + val f : java.io.File? = null Collections.emptyList Collections.emptyList @@ -27,7 +27,7 @@ fun test(l : java.util.List) { List - val o = "sdf" as Object + val o = "sdf" as Object try { // ... diff --git a/idea/testData/checker/Unresolved.jet b/idea/testData/checker/Unresolved.jet index 2d56e915eb7..159fe931f0b 100644 --- a/idea/testData/checker/Unresolved.jet +++ b/idea/testData/checker/Unresolved.jet @@ -1,13 +1,13 @@ namespace unresolved fun testGenericArgumentsCount() { - val p1: Tuple2 = (2, 2) - val p2: Tuple2 = (2, 2) + val p1: Tuple2 = (2, 2) + val p2: Tuple2 = (2, 2) } fun testUnresolved() { if (a is String) { - val s = a + val s = a } foo(a) val s = "s" diff --git a/idea/testData/checker/Variance.jet b/idea/testData/checker/Variance.jet index 0d173e86dc8..da4384f88bb 100644 --- a/idea/testData/checker/Variance.jet +++ b/idea/testData/checker/Variance.jet @@ -8,13 +8,13 @@ abstract class Usual {} fun foo(c: Consumer, p: Producer, u: Usual) { val c1: Consumer = c - val c2: Consumer = c1 + val c2: Consumer = c1 val p1: Producer = p - val p2: Producer = p1 + val p2: Producer = p1 val u1: Usual = u - val u2: Usual = u1 + val u2: Usual = u1 } //Arrays copy example diff --git a/idea/testData/checker/infos/Autocasts.jet b/idea/testData/checker/infos/Autocasts.jet index d84364c7330..d2acba03849 100644 --- a/idea/testData/checker/infos/Autocasts.jet +++ b/idea/testData/checker/infos/Autocasts.jet @@ -163,42 +163,42 @@ fun illegalWhenBlock(a: Any): Int { } fun declarations(a: Any?) { if (a is String) { - val p4: (Int, String) = (2, a) + val p4: (Int, String) = (2, a) } if (a is String?) { if (a != null) { - val s: String = a + val s: String = a } } if (a != null) { if (a is String?) { - val s: String = a + val s: String = a } } } fun vars(a: Any?) { - var b: Int = 0 + var b: Int = 0 if (a is Int) { - b = a + b = a } } fun tuples(a: Any?) { if (a != null) { - val s: (Any, String) = (a, a) + val s: (Any, String) = (a, a) } if (a is String) { - val s: (Any, String) = (a, a) + val s: (Any, String) = (a, a) } fun illegalTupleReturnType(): (Any, String) = (a, a) if (a is String) { fun legalTupleReturnType(): (Any, String) = (a, a) } - val illegalFunctionLiteral: Function0 = { a } - val illegalReturnValueInFunctionLiteral: Function0 = { (): Int => a } + val illegalFunctionLiteral: Function0 = { a } + val illegalReturnValueInFunctionLiteral: Function0 = { (): Int => a } if (a is Int) { - val legalFunctionLiteral: Function0 = { a } - val alsoLegalFunctionLiteral: Function0 = { (): Int => a } + val legalFunctionLiteral: Function0 = { a } + val alsoLegalFunctionLiteral: Function0 = { (): Int => a } } } fun returnFunctionLiteralBlock(a: Any?): Function0 { @@ -225,7 +225,7 @@ fun mergeAutocasts(a: Any?) { is String, is Any => a.compareTo("") } if (a is String && a is Any) { - val i: Int = a.compareTo("") + val i: Int = a.compareTo("") } if (a is String && a.compareTo("") == 0) {} if (a is String || a.compareTo("") == 0) {} @@ -235,9 +235,9 @@ fun mergeAutocasts(a: Any?) { fun f(): String { var a: Any = 11 if (a is String) { - val i: String = a + val i: String = a a.compareTo("f") - val f: Function0 = { a } + val f: Function0 = { a } return a } return "" diff --git a/idea/testData/checker/infos/WrapIntoRef.jet b/idea/testData/checker/infos/WrapIntoRef.jet index fb938acda53..886b601bbfa 100644 --- a/idea/testData/checker/infos/WrapIntoRef.jet +++ b/idea/testData/checker/infos/WrapIntoRef.jet @@ -1,30 +1,30 @@ fun refs() { - var a = 1 - val v = { - a = 2 + var a = 1 + val v = { + a = 2 } - var x = 1 - val b = object { + var x = 1 + val b = object { fun foo() { - x = 2 + x = 2 } } - var y = 1 + var y = 1 fun foo() { - y = 1 + y = 1 } } fun refsPlusAssign() { var a = 1 - val v = { + val v = { a += 2 } var x = 1 - val b = object { + val b = object { fun foo() { x += 2 } diff --git a/idea/testData/checker/regression/AssignmentsUnderOperators.jet b/idea/testData/checker/regression/AssignmentsUnderOperators.jet index 2acdbfdd984..c8825f90731 100644 --- a/idea/testData/checker/regression/AssignmentsUnderOperators.jet +++ b/idea/testData/checker/regression/AssignmentsUnderOperators.jet @@ -2,5 +2,5 @@ fun test() { var a : Any? = null if (a is Any) else a = null; while (a is Any) a = null - while (true) a = null + while (true) a = null } \ No newline at end of file diff --git a/idea/testData/checker/regression/CoercionToUnit.jet b/idea/testData/checker/regression/CoercionToUnit.jet index 5d814eadc9e..ec8c8e32275 100644 --- a/idea/testData/checker/regression/CoercionToUnit.jet +++ b/idea/testData/checker/regression/CoercionToUnit.jet @@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1 fun test() : Int { foo(1) - val a : fun() : Unit = { + val a : fun() : Unit = { foo(1) } return 1 diff --git a/idea/testData/checker/regression/DoubleDefine.jet b/idea/testData/checker/regression/DoubleDefine.jet index ebbda575d07..09e2f188993 100644 --- a/idea/testData/checker/regression/DoubleDefine.jet +++ b/idea/testData/checker/regression/DoubleDefine.jet @@ -32,7 +32,7 @@ fun evaluateAdd(expr: StringBuilder, numbers: ArrayList): Int { fun evaluate(expr: StringBuilder, numbers: ArrayList): Int { val lhs = evaluateAdd(expr, numbers) if (expr.length() > 0) { - val c = expr.charAt(0) + val c = expr.charAt(0) expr.deleteCharAt(0) } return lhs diff --git a/idea/testData/checker/regression/Jet124.jet b/idea/testData/checker/regression/Jet124.jet index 317b1438f41..48aa4644dea 100644 --- a/idea/testData/checker/regression/Jet124.jet +++ b/idea/testData/checker/regression/Jet124.jet @@ -1,8 +1,8 @@ fun foo1() : fun (Int) : Int = { (x: Int) => x } fun foo() { - val h : fun (Int) : Int = foo1(); + val h : fun (Int) : Int = foo1(); h(1) - val m : fun (Int) : Int = {(a : Int) => 1}//foo1() + val m : fun (Int) : Int = {(a : Int) => 1}//foo1() m(1) } \ No newline at end of file diff --git a/idea/testData/checker/regression/Jet183.jet b/idea/testData/checker/regression/Jet183.jet index 58712e5db73..645c93f52c4 100644 --- a/idea/testData/checker/regression/Jet183.jet +++ b/idea/testData/checker/regression/Jet183.jet @@ -18,5 +18,5 @@ enum class Foo { fun box() { - val x: ProtocolState = ProtocolState.WAITING + val x: ProtocolState = ProtocolState.WAITING } diff --git a/idea/testData/checker/regression/ScopeForSecondaryConstructors.jet b/idea/testData/checker/regression/ScopeForSecondaryConstructors.jet index 80b5a321d89..f4516941508 100644 --- a/idea/testData/checker/regression/ScopeForSecondaryConstructors.jet +++ b/idea/testData/checker/regression/ScopeForSecondaryConstructors.jet @@ -11,7 +11,7 @@ bar = 1 this.bar 1 : Int - val a : Int =1 + val a : Int =1 this : Foo } } From 850cd190f8126d8a3c46ec0ac35975f572bff881 Mon Sep 17 00:00:00 2001 From: svtk Date: Thu, 24 Nov 2011 16:00:10 +0400 Subject: [PATCH 09/17] Exception on incomplete code fixed --- .../org/jetbrains/jet/lang/resolve/OverrideResolver.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java index 161eb5bcd7a..0ea7d1e60aa 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java @@ -110,16 +110,17 @@ public class OverrideResolver { Set manyImpl = Sets.newLinkedHashSet(); collectMissingImplementations(classDescriptor, abstractNoImpl, manyImpl); - PsiElement nameIdentifier = klass; + PsiElement nameIdentifier = null; if (klass instanceof JetClass) { nameIdentifier = ((JetClass) klass).getNameIdentifier(); } else if (klass instanceof JetObjectDeclaration) { nameIdentifier = ((JetObjectDeclaration) klass).getNameIdentifier(); } + PsiElement elementToMark = nameIdentifier != null ? nameIdentifier : klass; for (CallableMemberDescriptor memberDescriptor : manyImpl) { - context.getTrace().report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor)); + context.getTrace().report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(elementToMark, klass, memberDescriptor)); break; } @@ -129,7 +130,7 @@ public class OverrideResolver { } for (CallableMemberDescriptor memberDescriptor : abstractNoImpl) { - context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor)); + context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(elementToMark, klass, memberDescriptor)); break; } From c80301a13d023d5a08d70bb67e3e481bb0f0bc5d Mon Sep 17 00:00:00 2001 From: svtk Date: Thu, 24 Nov 2011 16:02:29 +0400 Subject: [PATCH 10/17] Changed 'getOverriddenDescriptors' method for accessors (get accessors of overridden properties) --- .../descriptors/PropertyAccessorDescriptor.java | 14 ++++++++++++++ .../jet/lang/descriptors/PropertyDescriptor.java | 4 ++-- .../lang/descriptors/PropertyGetterDescriptor.java | 9 ++------- .../lang/descriptors/PropertySetterDescriptor.java | 9 ++------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyAccessorDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyAccessorDescriptor.java index cf0a0c8be05..93f2000146d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyAccessorDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyAccessorDescriptor.java @@ -1,5 +1,6 @@ package org.jetbrains.jet.lang.descriptors; +import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; @@ -7,6 +8,7 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor; import java.util.Collections; import java.util.List; +import java.util.Set; /** * @author abreslav @@ -95,4 +97,16 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm public PropertyAccessorDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) { throw new UnsupportedOperationException("Accessors must be copied by the corresponding property"); } + + protected Set getOverriddenDescriptors(boolean isGetter) { + Set overriddenProperties = getCorrespondingProperty().getOverriddenDescriptors(); + Set overriddenAccessors = Sets.newHashSet(); + for (PropertyDescriptor overriddenProperty : overriddenProperties) { + PropertyAccessorDescriptor accessorDescriptor = isGetter ? overriddenProperty.getGetter() : overriddenProperty.getSetter(); + if (accessorDescriptor != null) { + overriddenAccessors.add(accessorDescriptor); + } + } + return overriddenAccessors; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java index 354979ecac9..69555990589 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java @@ -27,6 +27,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab private final ReceiverDescriptor receiver; private final ReceiverDescriptor expectedThisObject; private final Set overriddenProperties = Sets.newLinkedHashSet(); + private final Set overridingProperties = Sets.newLinkedHashSet(); private final List typeParemeters = Lists.newArrayListWithCapacity(0); private final PropertyDescriptor original; private PropertyGetterDescriptor getter; @@ -190,7 +191,6 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab @Override public Set getOverriddenDescriptors() { return overriddenProperties; - } @NotNull @@ -212,7 +212,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab DescriptorUtils.convertModality(setter.getModality(), makeNonAbstract), setter.getVisibility(), propertyDescriptor, Lists.newArrayList(setter.getAnnotations()), - setter.hasBody(), setter.isDefault());; + setter.hasBody(), setter.isDefault()); propertyDescriptor.initialize(DescriptorUtils.copyTypeParameters(propertyDescriptor, getTypeParameters()), newGetter, newSetter); return propertyDescriptor; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java index 01bde2bf062..4181da25779 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java @@ -15,7 +15,6 @@ import java.util.Set; * @author abreslav */ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor { - private final Set overriddenGetters = Sets.newHashSet(); private JetType returnType; public PropertyGetterDescriptor(@NotNull PropertyDescriptor correspondingProperty, @NotNull List annotations, @NotNull Modality modality, @NotNull Visibility visibility, @Nullable JetType returnType, boolean hasBody, boolean isDefault) { @@ -25,12 +24,8 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor { @NotNull @Override - public Set getOverriddenDescriptors() { - return overriddenGetters; - } - - public void addOverriddenFunction(@NotNull PropertyGetterDescriptor overriddenGetter) { - overriddenGetters.add(overriddenGetter); + public Set getOverriddenDescriptors() { + return super.getOverriddenDescriptors(true); } @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java index d5f2038a282..7319cb5ce3b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java @@ -16,7 +16,6 @@ import java.util.Set; public class PropertySetterDescriptor extends PropertyAccessorDescriptor { private MutableValueParameterDescriptor parameter; - private final Set overriddenSetters = Sets.newHashSet(); public PropertySetterDescriptor(@NotNull Modality modality, @NotNull Visibility visibility, @NotNull PropertyDescriptor correspondingProperty, @NotNull List annotations, boolean hasBody, boolean isDefault) { super(modality, visibility, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody, isDefault); @@ -33,12 +32,8 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor { @NotNull @Override - public Set getOverriddenDescriptors() { - return overriddenSetters; - } - - public void setOverriddenFunction(@NotNull PropertySetterDescriptor overriddenSetter) { - overriddenSetters.add(overriddenSetter); + public Set getOverriddenDescriptors() { + return super.getOverriddenDescriptors(false); } @NotNull From a9138eebc6d0924b5efb116ec80d895dc925103b Mon Sep 17 00:00:00 2001 From: svtk Date: Thu, 24 Nov 2011 16:10:23 +0400 Subject: [PATCH 11/17] test for obsolete kt302 --- .../quick/regressions/kt302.jet | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 compiler/testData/checkerWithErrorTypes/quick/regressions/kt302.jet diff --git a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt302.jet b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt302.jet new file mode 100644 index 00000000000..df3d68e0d55 --- /dev/null +++ b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt302.jet @@ -0,0 +1,13 @@ +// KT-302 Report an error when inheriting many implementations of the same member + +namespace kt302 + +trait A { + open fun foo() {} +} + +trait B { + open fun foo() {} +} + +class C : A, B {} //should be error here \ No newline at end of file From aa007d415d82dfbaad3fe5d038f6e260a003d179 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 24 Nov 2011 15:31:21 +0300 Subject: [PATCH 12/17] Moved to full, since the test uses JDK --- .../{quick/regressions => full/regression}/kt588.jet | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename compiler/testData/checkerWithErrorTypes/{quick/regressions => full/regression}/kt588.jet (100%) diff --git a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt588.jet b/compiler/testData/checkerWithErrorTypes/full/regression/kt588.jet similarity index 100% rename from compiler/testData/checkerWithErrorTypes/quick/regressions/kt588.jet rename to compiler/testData/checkerWithErrorTypes/full/regression/kt588.jet From 702305ad2cc9aec9d7536dcb9f422e3e2c3a9a73 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 24 Nov 2011 16:38:24 +0400 Subject: [PATCH 13/17] KT-515 fixed in platform code, re-enable java->kotlin resolve --- idea/src/META-INF/plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index eadcca9d8bd..fe7b457af02 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -57,7 +57,7 @@ - + From e8d41ea6c7aea3a49faec6c220897f072e412d42 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Thu, 24 Nov 2011 17:20:22 +0400 Subject: [PATCH 14/17] Revert "fix DescriptionRenderer failure if FunctionDescriptor.getReturnType returns null" Problem will be fixed by removing @NotNull modifier. This reverts commit fed075b0cafcdae2ea97bf780bd06ed69df675f3. --- .../jet/lang/descriptors/CallableDescriptor.java | 4 ---- .../jet/lang/descriptors/FunctionDescriptorImpl.java | 6 ------ .../jet/lang/descriptors/PropertyDescriptor.java | 5 ----- .../jet/lang/descriptors/PropertyGetterDescriptor.java | 6 ------ .../jet/lang/descriptors/PropertySetterDescriptor.java | 5 ----- .../jet/lang/descriptors/VariableDescriptorImpl.java | 6 ------ .../org/jetbrains/jet/resolve/DescriptorRenderer.java | 9 +++------ 7 files changed, 3 insertions(+), 38 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableDescriptor.java index afc9560badb..4e78d2c81f5 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableDescriptor.java @@ -1,7 +1,6 @@ package org.jetbrains.jet.lang.descriptors; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.TypeSubstitutor; @@ -25,9 +24,6 @@ public interface CallableDescriptor extends DeclarationDescriptor { @NotNull JetType getReturnType(); - @Nullable - JetType getReturnTypeSafe(); - @NotNull @Override CallableDescriptor getOriginal(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java index 7f8a7943a88..ef3ab5aefa0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java @@ -125,12 +125,6 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements return unsubstitutedReturnType; } - @Override - @Nullable - public JetType getReturnTypeSafe() { - return unsubstitutedReturnType; - } - @NotNull @Override public FunctionDescriptor getOriginal() { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java index bc09461d530..69555990589 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java @@ -119,11 +119,6 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab return getOutType(); } - @Override - @Nullable - public JetType getReturnTypeSafe() { - return getOutType(); - } public boolean isVar() { return isVar; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java index 491a0afa50b..4181da25779 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java @@ -40,12 +40,6 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor { return returnType; } - @Override - @Nullable - public JetType getReturnTypeSafe() { - return returnType; - } - @Override public R accept(DeclarationDescriptorVisitor visitor, D data) { return visitor.visitPropertyGetterDescriptor(this, data); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java index cd1fc09caa0..7319cb5ce3b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java @@ -48,11 +48,6 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor { return JetStandardClasses.getUnitType(); } - @Override - public JetType getReturnTypeSafe() { - return getReturnType(); - } - @Override public R accept(DeclarationDescriptorVisitor visitor, D data) { return visitor.visitPropertySetterDescriptor(this, data); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/VariableDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/VariableDescriptorImpl.java index 827fcbeab9a..6daefbce285 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/VariableDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/VariableDescriptorImpl.java @@ -89,10 +89,4 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorImpl i public JetType getReturnType() { return getOutType(); } - - @Override - @Nullable - public JetType getReturnTypeSafe() { - return getOutType(); - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java b/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java index 8b2ccbd024a..a378e31d39b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java +++ b/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java @@ -73,11 +73,7 @@ public class DescriptorRenderer implements Renderer { } public String renderType(JetType type) { - if (type == null) { - return escape(""); - } else { - return escape(type.toString()); - } + return escape(type.toString()); } protected String escape(String s) { @@ -226,7 +222,8 @@ public class DescriptorRenderer implements Renderer { renderName(descriptor, builder); renderValueParameters(descriptor, builder); - builder.append(" : ").append(escape(renderType(descriptor.getReturnTypeSafe()))); + // TODO: getReturnType may be uninitialized and throw IllegalStateException // stepan.koltsov@ 2011-11-21 + builder.append(" : ").append(escape(renderType(descriptor.getReturnType()))); return super.visitFunctionDescriptor(descriptor, builder); } From 9bd98cdf2b9ac1f29b3aa2191e248e9a6f12bf6c Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Thu, 24 Nov 2011 17:22:27 +0400 Subject: [PATCH 15/17] disable TypeInfoTest.testIsWithGenerics (test is wrong, see http://youtrack.jetbrains.net/issue/KT-612) --- compiler/tests/org/jetbrains/jet/codegen/TypeInfoTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/tests/org/jetbrains/jet/codegen/TypeInfoTest.java b/compiler/tests/org/jetbrains/jet/codegen/TypeInfoTest.java index da349baae39..2abfd9db28e 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/TypeInfoTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/TypeInfoTest.java @@ -61,6 +61,9 @@ public class TypeInfoTest extends CodegenTestCase { } public void testIsWithGenerics() throws Exception { + // TODO: http://youtrack.jetbrains.net/issue/KT-612 + if (true) return; + loadFile(); System.out.println(generateToText()); Method foo = generateFunction(); From 2fcc18f08b75581d75c3dbfab9ba056d287f7711 Mon Sep 17 00:00:00 2001 From: svtk Date: Thu, 24 Nov 2011 18:53:29 +0400 Subject: [PATCH 16/17] new method for import helper --- .../plugin/quickfix/ImportClassHelper.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ImportClassHelper.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ImportClassHelper.java index a8471ab2e96..5bc1c75db9b 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ImportClassHelper.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ImportClassHelper.java @@ -2,6 +2,7 @@ package org.jetbrains.jet.plugin.quickfix; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.JetType; @@ -13,24 +14,33 @@ import java.util.List; * @author svtk */ public class ImportClassHelper { - public static void perform(@NotNull JetType type, @NotNull PsiElement element, @NotNull PsiElement newElement) { - PsiElement parent = element; + public static void perform(@NotNull JetType type, @NotNull PsiElement elementToReplace, @NotNull PsiElement newElement) { + if (JetPluginUtil.checkTypeIsStandard(type, elementToReplace.getProject()) || ErrorUtils.isError(type.getMemberScope().getContainingDeclaration())) { + elementToReplace.replace(newElement); + return; + } + perform(JetPluginUtil.computeTypeFullName(type), elementToReplace, newElement); + } + + public static void perform(@NotNull String typeFullName, @NotNull JetNamespace namespace) { + perform(typeFullName, namespace, null, null); + } + + public static void perform(@NotNull String typeFullName, @NotNull PsiElement elementToReplace, @NotNull PsiElement newElement) { + PsiElement parent = elementToReplace; while (!(parent instanceof JetNamespace)) { parent = parent.getParent(); assert parent != null; } - JetNamespace namespace = (JetNamespace) parent; + perform(typeFullName, (JetNamespace) parent, elementToReplace, newElement); + } + + public static void perform(@NotNull String typeFullName, @NotNull JetNamespace namespace, @Nullable PsiElement elementToReplace, @Nullable PsiElement newElement) { List importDirectives = namespace.getImportDirectives(); - if (JetPluginUtil.checkTypeIsStandard(type, element.getProject()) || ErrorUtils.isError(type.getMemberScope().getContainingDeclaration())) { - element.replace(newElement); - return; - } - - String typeFullName = JetPluginUtil.computeTypeFullName(type); - - JetImportDirective newDirective = JetPsiFactory.createImportDirective(element.getProject(), typeFullName); + JetImportDirective newDirective = JetPsiFactory.createImportDirective(namespace.getProject(), typeFullName); + String lineSeparator = System.getProperty("line.separator"); if (!importDirectives.isEmpty()) { boolean isPresent = false; for (JetImportDirective directive : importDirectives) { @@ -42,7 +52,7 @@ public class ImportClassHelper { if (!isPresent) { JetImportDirective lastDirective = importDirectives.get(importDirectives.size() - 1); lastDirective.getParent().addAfter(newDirective, lastDirective); - lastDirective.getParent().addAfter(JetPsiFactory.createWhiteSpace(element.getProject(), "\n"), lastDirective); + lastDirective.getParent().addAfter(JetPsiFactory.createWhiteSpace(namespace.getProject(), lineSeparator), lastDirective); } } else { @@ -50,9 +60,10 @@ public class ImportClassHelper { assert !declarations.isEmpty(); JetDeclaration firstDeclaration = declarations.iterator().next(); firstDeclaration.getParent().addBefore(newDirective, firstDeclaration); - firstDeclaration.getParent().addBefore(JetPsiFactory.createWhiteSpace(element.getProject(), "\n\n"), firstDeclaration); + firstDeclaration.getParent().addBefore(JetPsiFactory.createWhiteSpace(namespace.getProject(), lineSeparator + lineSeparator), firstDeclaration); + } + if (elementToReplace != null && newElement != null && elementToReplace != newElement) { + elementToReplace.replace(newElement); } - element.replace(newElement); - parent.replace(namespace); } } From 1e63c6257cb5ac57bfe58e45afff47aaa881a204 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 24 Nov 2011 21:14:50 +0300 Subject: [PATCH 17/17] Throw exception if compilation fails on server --- .../jetbrains/jet/codegen/GenerationState.java | 2 ++ .../jet/lang/resolve/java/AnalyzerFacade.java | 16 +++------------- .../jet/lang/diagnostics/DiagnosticUtils.java | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java index 56b432cf2c9..21c99a991f5 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java @@ -10,6 +10,7 @@ import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; +import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; @@ -113,6 +114,7 @@ public class GenerationState { } catch (Throwable e) { errorHandler.reportException(e, namespace.getContainingFile().getVirtualFile().getUrl()); + DiagnosticUtils.throwIfRunningOnServer(e); } } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java index 6ad38396927..ad4e1f20d74 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java @@ -11,6 +11,7 @@ import com.intellij.psi.util.PsiModificationTracker; import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; +import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.JetDeclaration; import org.jetbrains.jet.lang.psi.JetFile; @@ -68,18 +69,8 @@ public class AnalyzerFacade { throw e; } catch (Throwable e) { - // This is needed for the Web Demo server to log the exceptions coming from the analyzer instead of showing them in the editor. - if (System.getProperty("kotlin.running.in.server.mode", "false").equals("true")) { - if (e instanceof RuntimeException) { - RuntimeException runtimeException = (RuntimeException) e; - throw runtimeException; - } - if (e instanceof Error) { - Error error = (Error) e; - throw error; - } - throw new RuntimeException(e); - } + DiagnosticUtils.throwIfRunningOnServer(e); + e.printStackTrace(); BindingTraceContext bindingTraceContext = new BindingTraceContext(); bindingTraceContext.report(Errors.EXCEPTION_WHILE_ANALYZING.on(file, e)); @@ -93,5 +84,4 @@ public class AnalyzerFacade { } return bindingContextCachedValue.getValue(); } - } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java index 0ff433add71..0e85d64ce6d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java @@ -81,4 +81,19 @@ public class DiagnosticUtils { } return position; } + + public static void throwIfRunningOnServer(Throwable e) { + // This is needed for the Web Demo server to log the exceptions coming from the analyzer instead of showing them in the editor. + if (System.getProperty("kotlin.running.in.server.mode", "false").equals("true")) { + if (e instanceof RuntimeException) { + RuntimeException runtimeException = (RuntimeException) e; + throw runtimeException; + } + if (e instanceof Error) { + Error error = (Error) e; + throw error; + } + throw new RuntimeException(e); + } + } }