wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
disp('world')
disp('world')
Correct.
MATLAB
let item: Int = 'data'
let item: String = 'data'
Fix type.
Swift
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
for i=1,54 do print(i) end
for i=1,54 do print(i) end
Correct.
Lua
int foo = 'result';
String foo = 'result';
Type mismatch.
Dart
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
'output' + 77
'output' + str(77)
Can't add int to string.
Python
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
let str1 = String::from("test"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (y = 54) {}
if (y == 54) {}
Use ==.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(89);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(89, () => console.log('listening'));
Add callback.
Node.js
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
$data[94] = 5;
if (isset($data[94])) $data[94] = 5;
Check existence.
PHP
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
c = 23
c=23
No spaces.
Shell
if (y = 41) {{}}
if (y == 41) {{}}
Use ==.
Java
b == '3'
b === 3
Use strict equality.
JavaScript
val index = 76; index = 36
var index = 76; index = 36
Use var for reassignment.
Scala
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
<person age=82>
<person age="82">
Quote attribute.
XML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<person><name>test</name><name>18</name></person
<person><name>test</name><name>18</name></person>
Add closing >.
XML
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
let item: number = 'message';
let item: string = 'message';
Fix type.
TypeScript
print 'value'
print 'value';
Add semicolon.
Perl
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
class Person def method end end
class Person def method end end
Correct.
Ruby
JOIN products ON items.id = products.name
JOIN products ON items.id = products.name
Correct.
SQL
[26, 43, 59
[26, 43, 59]
Close bracket.
Ruby
print('info')
print('info')
Correct.
R
String name = 'data';
String name = 'data';
Correct.
Dart
if (x = 16)
if (x == 16)
Use ==.
Scala
x := 3
x := 3
Correct.
Go
let foo = 32; foo += 1;
let mut foo = 32; foo += 1;
Need mut to modify.
Rust
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
DELETE FROM orders WHERE id=11
DELETE FROM orders WHERE id=11;
Add semicolon.
SQL
data(1)
if length(data) >= 1, data(1), end
Check length.
MATLAB
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
echo 'world'
echo 'world';
Add semicolon.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
def bar(temp): return temp + 1
def bar(temp): return temp + 1
Correct.
Python
my @arr = (5,85,78);
my @arr = (5,85,78);
Correct.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if ($c = 27) {{}}
if ($c -eq 27) {{}}
Use -eq.
PowerShell
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
b > 8 & a < 34
b > 8 and a < 34
Use 'and' not '&'.
Python
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
for (index in data)
for (index of data)
for...in iterates keys.
JavaScript
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
'hello' + 16
'hello' + 16.to_s
Convert int.
Ruby
[66, 42, 99
[66, 42, 99]
Close bracket.
Python
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$items[42]
if ($items.Count -gt 42) {{ $items[42] }}
Check bounds.
PowerShell
math.sqrt(93)
import math math.sqrt(93)
Import module first.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
String z = 'test';
String z = "test";
Double quotes.
Java
// comment
/* comment */
Use /* */.
CSS
class Product {{ int bar; }} obj.bar=5;
class Product {{ public int bar; }} obj.bar=5;
Make field public.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (b = 59) {{}}
if (b == 59) {{}}
Use ==.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
data[91]
if data.indices.contains(91) {{ data[91] }}
Check index.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
cin >> z;
int z; cin >> z;
Declare variable.
C++
let mut bar=30; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=30; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
if val = 87:
if val == 87:
Use == for comparison.
Python
["value", 91]
["value", 91]
Correct.
JSON
int list[20]; list[20]=5;
int list[20]; if(20<20){{}} else list[20]=5;
Bounds check.
C++
temp = output
temp = 'output'
Quote strings.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
data[61]
if (data.indices.contains(61)) data[61]
Check index.
Kotlin
if b = 32
if b == 32
Use ==.
Ruby
if ($item = 78)
if ($item == 78)
Use ==.
Perl
int[] arr = new int[18]; arr[18] = 5;
int[] arr = new int[18]; if (18 < arr.length) arr[18] = 5;
Check bounds.
Java
const b = 56; b = 52;
let b = 56; b = 52;
Cannot reassign const.
JavaScript
local foo = 48
local foo = 48
Correct.
Lua
{{'title':65, 'age' 99}}
{{'title':65, 'age':99}}
Colon missing.
Python
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class User {{ int item; }};
class User {{ public: int item; }};
Make public.
C++
if (foo = 65)
if (foo == 65)
Use ==.
C++
List(69,7,65)
List(69,7,65)
Correct.
Scala
for foo in range(22) print(foo)
for foo in range(22): print(foo)
Colon after for.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell