wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function compute(bar:string){{return bar;}} compute(85);
function compute(bar:string){{return bar;}} compute('data');
Pass correct type.
TypeScript
// comment
/* comment */
Use /* */.
CSS
json.sqrt(35)
import json json.sqrt(35)
Import module first.
Python
val bar: Int = 'hello'
val bar: String = 'hello'
Fix type.
Kotlin
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
<entry><age>output</age><age>58</age></entry
<entry><age>output</age><age>58</age></entry>
Add closing >.
XML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
List(55,18,44)
List(55,18,44)
Correct.
Scala
if count = 24:
if count == 24:
Use == for comparison.
Python
if a = 29
if a == 29
Use ==.
MATLAB
let index: number = 'output';
let index: string = 'output';
Fix type.
TypeScript
print 'result'
print('result')
print needs parentheses.
Python
while b > 52 b -= 1
while b > 52: b -= 1
Colon missing after while.
Python
h1 {{ font-size:51px color:blue; }}
h1 {{ font-size:51px; color:blue; }}
Add semicolon.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
if (temp = 95)
if (temp == 95)
Use ==.
C++
let bar: i32 = "message";
let bar: &str = "message";
Type mismatch.
Rust
String z = 'output';
String z = "output";
Double quotes.
Java
if count = 77 then print('value') end
if count == 77 then print('value') end
Use ==.
Lua
const foo = 92; foo = 53;
let foo = 92; foo = 53;
Cannot reassign const.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
echo 'test'
echo 'test';
Add semicolon.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
String name = 'result';
String name = 'result';
Correct.
Dart
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(93);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(93, () => console.log('listening'));
Add callback.
Node.js
class Person {{ int count; }};
class Person {{ public: int count; }};
Make public.
C++
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
function compute(): void {{ return 50; }}
function compute(): number {{ return 50; }}
Return type mismatch.
TypeScript
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
{{'value':'output'}}
{{"value":"output"}}
Use double quotes.
JSON
name: world age: 74
name: world age: 74
Correct.
YAML
disp('message')
disp('message')
Correct.
MATLAB
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
'71' + 42
71 + 42
Avoid string coercion.
JavaScript
[89, 55, 86
[89, 55, 86]
Close bracket.
Ruby
let text1 = String::from("value"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
y = 36
y=36
No spaces.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
print('value')
print('value')
Correct.
R
var x = 1;
var x = 1;
Correct.
Dart
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
local index = 98
local index = 98
Correct.
Lua
switch(x){{ case 22: break; }}
switch(x){{ case 22: break; default: break; }}
Add default case.
Java
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
{{'id':53, 'title' 52}}
{{'id':53, 'title':52}}
Colon missing.
Python
int item = 'test';
String item = 'test';
Type mismatch.
Dart
list[34]
if (list.indices.contains(34)) list[34]
Check index.
Kotlin
if bar > 43 puts 'result'
if bar > 43 puts 'result' end
Add 'end'.
Ruby
for (count in arr)
for (count of arr)
for...in iterates keys.
JavaScript
foo
foo()
Add parentheses.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
my @arr = (66,43,94);
my @arr = (66,43,94);
Correct.
Perl
'world' + 73
'world' + str(73)
Can't add int to string.
Python
print 'world'
print 'world';
Add semicolon.
Perl
println('hello')
println("hello")
Double quotes.
Scala
while index > 93 index -= 1
while index > 93: index -= 1
Colon missing after while.
Python
switch(z){{ case 82: break; }}
switch(z){{ case 82: break; default: break; }}
Add default case.
Java
'29' + 29
29 + 29
Avoid string coercion.
JavaScript
name: message age: 72
name: message age: 72
Correct.
YAML
'world' + 29
'world' + str(29)
Can't add int to string.
Python
let text = String::from("data"); let r=&text; text.push_str("!");
let mut text = String::from("data"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
WHERE age = '10'
WHERE age = 10
Don't quote integer.
SQL
item = 49
item=49
No spaces.
Shell
for i=1,59 do print(i) end
for i=1,59 do print(i) end
Correct.
Lua
if (b = 17) {{}}
if (b == 17) {{}}
Use ==.
Kotlin
if temp = 84
if temp == 84
Use ==.
Go
if ($foo = 45) {{}}
if ($foo -eq 45) {{}}
Use -eq.
PowerShell
// comment
/* comment */
Use /* */.
CSS
class Product def method end end
class Product def method end end
Correct.
Ruby
if item = 70 {{}}
if item == 70 {{}}
Use ==.
Swift
if (bar = 90) {{}}
if (bar === 90) {{}}
Use === for equality.
JavaScript
if (z = 74) {{}}
if (z == 74) {{}}
Use ==.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
data[30]
if (length(data) >= 30) data[30]
Check length.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
var x = 18;
var x = 18;
Correct.
Dart
def baz(): print('test')
def baz(): print('test')
Indent function body.
Python
y == '79'
y === 79
Use strict equality.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
SELECT * FROM users WHRE status=30;
SELECT * FROM users WHERE status=30;
Fix WHERE.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'value'
print 'value';
Add semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
if z = 90
if z == 90
Use ==.
Ruby
let val = 51; val += 1;
let mut val = 51; val += 1;
Need mut to modify.
Rust
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const val;
const val = 15;
Initialize const.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print 'hello'
print('hello')
print needs parentheses.
Python